Progress on ca

==============
Must be tested : insert for ACH VEN ODS
This commit is contained in:
Dany De Bontridder 2010-07-02 06:53:06 +00:00
parent 6caef227d9
commit b9a9f6e7ef
9 changed files with 194 additions and 111 deletions

View file

@ -322,7 +322,7 @@ case 'rmf':
$op->oa_date=$row_ca['j_date'];
$op->oa_group=$group;
$op->oa_description=$_REQUEST['lib'];
$op->save_form_plan($_REQUEST,$count);
$op->save_form_plan($_REQUEST,$count,$row_ca['j_id']);
$count++;
} //if myereg
}//foreach

View file

@ -25,9 +25,8 @@
/*!\brief add a row for the CA
* \param p_table_id
* \param p_amount amount to reach
* \param p_count count of col.
*/
function add_row(p_table,p_seq,p_count) {
function add_row(p_table,p_seq) {
var mytable=g(p_table).tBodies[0];
if ( ! mytable ) {return;}
@ -44,13 +43,13 @@ function add_row(p_table,p_seq,p_count) {
for ( var i=0;i< rowToCopy.cells.length;i++) {
var cell=row.insertCell(i);
var txt=rowToCopy.cells[i].innerHTML;
txt=txt.replace(/row_1/g,"row_"+new_value);
// txt=txt.replace(/row_1/g,"row_"+new_value);
cell.innerHTML=txt;
}
// create the amount cell
row.cells[i-1].innerHTML='<input type="TEXT" name="val'+p_seq+"l"+new_value+'" id="val'+p_seq+"l"+new_value+'" size="6" style="border:solid 1px blue;color:black;background:#EDEDED;text-align:right" value="0">';
// row.cells[i-1].innerHTML='<input type="TEXT" name="val'+p_seq+"l"+new_value+'" id="val'+p_seq+"l"+new_value+'" onchange="format_number(this)" size="6" style="border:solid 1px blue;color:black;text-align:right" value="0">';
}
/*!

View file

@ -47,6 +47,7 @@ if ( ! isset($_REQUEST['gDossier'])) {
$array=array(
array(1,'Plan Analytic'),
array(2,'Poste Analytic'),
array(3,'Opération Analytic'),
array(11,'Periode'),
array(12,'verif.inc.php'),
array(13,'Rapport(class_acc_report'),
@ -100,6 +101,10 @@ case 2:
require_once("class_anc_account.php");
Anc_Account::test_me();
break;
case 3:
require_once ('class_anc_operation.php');
Anc_Operation::test_me();
break;
case 11:
require_once ('class_periode.php');
Periode::test_me();

View file

@ -993,13 +993,18 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
}
/*!
* \brief show the result of the array
* \brief show the result of the array to confirm
* before inserting
* \param $p_array array from the form
* \return string
*/
function show_summary($p_array) {
/**
*@todo add a call to verify ???
*/
$this->id=$p_array['p_jrn'];
if ( empty($p_array)) return 'Aucun r&eacute;sultat';
$anc=null;
extract($p_array);
$lPeriode=new Periode($this->db);
if ($this->check_periode() == true) {
@ -1007,6 +1012,8 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
} else {
$lPeriode->find_periode($date);
}
$owner=new own($this->db);
$ret="";
$ret.="<table>";
$ret.="<tr><td>"._('Date')." : </td><td>$date</td></tr>";
@ -1022,8 +1029,18 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
$ret.=_("Poste")." </th>";
$ret.="<th> "._("Montant")." </th>";
$ret.="<th>"._("Débit")."</th>";
/* if we use the AC */
if ($owner->MY_ANALYTIC!='nu') {
$anc=new Anc_Plan($this->db);
$a_anc=$anc->get_list();
$x=count($a_anc);
/* set the width of the col */
$ret.='<th colspan="'.$x.'">'._('Compt. Analytique').'</th>';
/* add hidden variables pa[] to hold the value of pa_id */
$ret.=Anc_Plan::hidden($a_anc);
}
$ret.="</tr>";
$own=new own($this->db);
$ret.=HtmlInput::hidden('date',$date);
$ret.=HtmlInput::hidden('desc',$desc);
@ -1072,14 +1089,18 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
$ret.="</td>";
// CA
if ( $own->MY_ANALYTIC!='nu') // use of AA
if ( $owner->MY_ANALYTIC!='nu') // use of AA
{
if ( myereg("^[6,7]+",$strPoste)) {
// show form
$op=new Anc_Operation($this->db);
$null=($own->MY_ANALYTIC=='op')?1:0;
$null=($owner->MY_ANALYTIC=='op')?1:0;
$p_array['pa_id']=$a_anc;
/* op is the operation it contains either a sequence or a jrnx.j_id */
$ret.=HtmlInput::hidden('op[]=',$i);
$ret.='<td>';
$ret.=$op->display_form_plan(null,$null,1,$count,round(${'amount'.$i},2));
$ret.=$op->display_form_plan($p_array,$null,1,$count,round(${'amount'.$i},2));
$ret.='</td>';
$count++;
}
@ -1186,8 +1207,8 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
/* suggest PJ ? */
$default_pj='';
$own=new Own($this->db);
if ( $own->MY_PJ_SUGGEST=='Y') {
$owner=new Own($this->db);
if ( $owner->MY_PJ_SUGGEST=='Y') {
$default_pj=$this->guess_pj();
}
$wPJ->value=(isset($e_pj))?$e_pj:$default_pj;
@ -1460,7 +1481,7 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
$internal=$this->compute_internal_code($seq);
$group=$this->db->get_next_seq("s_oa_group");
$own=new own($this->db);
$owner=new own($this->db);
$tot_amount=0;
$tot_deb=0;
$tot_cred=0;
@ -1512,7 +1533,7 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
$tot_amount+=round($acc_op->amount,2);
$tot_deb+=($acc_op->type=='d')?$acc_op->amount:0;
$tot_cred+=($acc_op->type=='c')?$acc_op->amount:0;
if ( $own->MY_ANALYTIC != "nu" )
if ( $owner->MY_ANALYTIC != "nu" )
{
if ( myereg("^[6,7]+",$poste)) {
@ -1523,7 +1544,7 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
$op->oa_date=$date;
$op->oa_debit=($acc_op->type=='d' )?'t':'f';
$op->oa_description=$desc;
$op->save_form_plan($p_array,$count);
$op->save_form_plan($p_array,$count,$j_id);
$count++;
}
}
@ -1711,9 +1732,9 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
* \return true if we are using the strict_mode
*/
function check_strict() {
$own=new Own($this->db);
if ( $own->MY_STRICT=='Y') return true;
if ( $own->MY_STRICT=='N') return false;
$owner=new Own($this->db);
if ( $owner->MY_STRICT=='Y') return true;
if ( $owner->MY_STRICT=='N') return false;
exit("Valeur invalid ".__FILE__.':'.__LINE__);
}
/*!
@ -1722,9 +1743,9 @@ function check_strict() {
* \return true if we are using the double encoding (date+periode)
*/
function check_periode() {
$own=new Own($this->db);
if ( $own->MY_CHECK_PERIODE=='Y') return true;
if ( $own->MY_CHECK_PERIODE=='N') return false;
$owner=new Own($this->db);
if ( $owner->MY_CHECK_PERIODE=='Y') return true;
if ( $owner->MY_CHECK_PERIODE=='N') return false;
exit("Valeur invalid ".__FILE__.':'.__LINE__);
}

View file

@ -416,7 +416,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger {
$op->oa_date=$e_date;
$op->oa_debit=($amount < 0 )?'t':'f';
$op->oa_description=FormatString($e_comm);
$op->save_form_plan($_POST,$i);
$op->save_form_plan($_POST,$i,$j_id);
}
// insert into quant_purchase
//-----
@ -1051,7 +1051,7 @@ array
function confirm($p_array) {
extract ($p_array);
$this->verify($p_array) ;
$anc=null;
// to show a select list for the analytic
// if analytic is op (optionnel) there is a blank line
$owner = new Own($this->db);
@ -1106,7 +1106,19 @@ array
$r.="<th>"._('quantité')."</th>";
$r.='<th> '._('Total')."</th>";
}
$r.=($owner->MY_ANALYTIC!='nu')?'<th>'._('Compt. Analytique').'</th>':'';
/* if we use the AC */
if ($owner->MY_ANALYTIC!='nu') {
$anc=new Anc_Plan($this->db);
$a_anc=$anc->get_list();
$x=count($a_anc);
/* set the width of the col */
$r.='<th colspan="'.$x.'">'._('Compt. Analytique').'</th>';
/* add hidden variables pa[] to hold the value of pa_id */
$r.=Anc_Plan::hidden($a_anc);
}
$r.='</tr>';
$tot_amount=0.0;
$tot_tva=0.0;
@ -1182,6 +1194,9 @@ array
$null=($owner->MY_ANALYTIC=='op')?1:0;
$r.='<td>';
$p_mode=1;
$p_array['pa_id']=$a_anc;
/* op is the operation it contains either a sequence or a jrnx.j_id */
$r.=HtmlInput::hidden('op[]=',$i);
$r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount);
$r.='</td>';
}

View file

@ -57,8 +57,12 @@ class Acc_Ledger_Sold extends Acc_Ledger {
public function verify($p_array) {
extract ($p_array);
/* check for a double reload */
if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
/**
*@todo REMOVE DEBUG FALSE
*/
if ( false && isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
throw new Exception (_('Double Encodage'),5);
/* check if we can write into this ledger */
$user=new User($this->db);
if ( $user->check_jrn($p_jrn) != 'W' )
@ -205,7 +209,6 @@ class Acc_Ledger_Sold extends Acc_Ledger {
*\note throw an Exception
*/
public function insert($p_array) {
extract ($p_array);
$this->verify($p_array) ;
@ -308,6 +311,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
if ( $owner->MY_ANALYTIC != "nu" )
{
var_dump("save anal");
// for each item, insert into operation_analytique */
$op=new Anc_Operation($this->db);
$op->oa_group=$group;
@ -315,7 +319,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$op->oa_date=$e_date;
$op->oa_debit=($amount < 0 )?'t':'f';
$op->oa_description=FormatString($e_comm);
$op->save_form_plan($_POST,$i);
$op->save_form_plan($_POST,$i,$j_id);
}
if ( $owner->MY_TVA_USE=='Y') {
/* save into quant_sold */
@ -531,7 +535,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
function confirm($p_array) {
extract ($p_array);
$this->verify($p_array) ;
$anc=null;
// to show a select list for the analytic & VAT USE
// if analytic is op (optionnel) there is a blank line
$owner = new Own($this->db);
@ -584,7 +588,17 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$r.='<th> '._('Montant TVA').'</th>';
$r.='<th>'._('Montant HTVA').'</th>';
}
$r.=($owner->MY_ANALYTIC!='nu')?'<th>'._('Compt. Analytique').'</th>':'';
/* if we use the AC */
if ($owner->MY_ANALYTIC!='nu') {
$anc=new Anc_Plan($this->db);
$a_anc=$anc->get_list();
$x=count($a_anc);
/* set the width of the col */
$r.='<th colspan="'.$x.'">'._('Compt. Analytique').'</th>';
/* add hidden variables pa[] to hold the value of pa_id */
$r.=Anc_Plan::hidden($a_anc);
}
$r.='</tr>';
$tot_amount=0.0;
$tot_tva=0.0;
@ -654,6 +668,9 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$null=($owner->MY_ANALYTIC=='op')?1:0;
$r.='<td>';
$p_mode=1;
$p_array['pa_id']=$a_anc;
/* op is the operation it contains either a sequence or a jrnx.j_id */
$r.=HtmlInput::hidden('op[]=',$i);
$r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount);
$r.='</td>';
}

View file

@ -289,7 +289,7 @@ class Anc_Operation
oa_row
from operation_analytique
where
j_id=$p_jid order by j_id,oa_row";
j_id=$p_jid order by j_id,pa_id,oa_row";
$ret=$this->db->exec_sql($sql);
$res=Database::fetch_all($ret);
if ( $res== false) return null;
@ -395,48 +395,45 @@ function get_balance($p_from,$p_to,$p_plan_id)
$result.='<table>';
$result.="<tr>".$plan->header()."<th>montant</th></tr>";
/* compute the number of rows */
$nb_row=count($p_array['pa_id'])/count($a_plan);
$nb_row=(!isset(${'nb_'.$table_id}))?1:${'nb_'.$table_id};
$result.=$hidden->input('nb_'.$table_id,$nb_row);
for ( $i=1; $i <= $nb_row;$i++) {
for ( $i=0; $i < $nb_row;$i++) {
$result.='<tr>';
$count=0;
foreach ($a_plan as $r_plan)
{
$count++;
$array=$this->db->make_array(
"select pa_id||'_'||po_id as value,".
"select po_id as value,".
" html_quote(po_name) as label from poste_analytique ".
" where pa_id = ".$r_plan['id'].
" order by po_name",$p_null);
$select =new ISelect("ta_".$p_seq."o".$count."row_".$i,$array);
$select =new ISelect("hplan[".$p_seq."][]",$array);
$select->table=0;
// view only or editable
// view only or editables
if ( $p_mode==1 ) {
// editable
$select->readonly=false;
$select->selected=(isset(${"ta_".$p_seq."o".$count."row_".$i}))?${"ta_".$p_seq."o".$count."row_".$i}:0;
if ( isset($hplan) )
$select->selected=$hplan[$p_seq][$count];
} else {
// view only
$select->readonly=true;
$select->selected=(isset(${"ta_".$p_seq."o".$count."row_".$i}))?${"ta_".$p_seq."o".$count."row_".$i}:0;
}
if ($p_mode==1)
$result.='<td id="'.$table_id.'td'.$count.'c'.$i.'">'.$select->input().'</td>';
else
$result.='<td>'.$select->input().'</td>';
else
$result.='<td>'.$select->display().'</td>';
$count++;
}
$value=new INum();
$value->name="val".$p_seq."l$i";
$value->name="val[".$p_seq."][]";
$value->size=6;
$value->value=(isset(${"val".$p_seq."l$i"}))?round(${"val".$p_seq."l$i"},2):$p_amount;
// $value->value=($p_doc=="form")?$p_amount:round(${"val".$p_seq."l$i"},2);
// $value->value=(isset(${"val".$p_seq."l$i"}))?round(${"val".$p_seq."l$i"},2):$p_amount;
$value->readonly=($p_mode==1)?false:true;
$result.='<td>'.$value->input().'</td>';
@ -447,7 +444,7 @@ function get_balance($p_from,$p_to,$p_plan_id)
$result.="</table>";
// add a button to add a row
$button=new IButton();
$button->javascript="add_row('".$p_id."$table_id',$p_seq,$count);";
$button->javascript="add_row('".$p_id."$table_id',$p_seq);";
$button->name="js".$p_id.$p_seq;
$button->label="Nouvelle ligne";
if ( $p_mode == 1 )
@ -475,41 +472,48 @@ function get_balance($p_from,$p_to,$p_plan_id)
* -oa_description
*
*/
function save_form_plan($p_array,$p_item) {
function save_form_plan($p_array,$p_item,$j_id) {
extract($p_array);
if ( !isset (${"nb_t".$p_item}) ) {
// echo __FILE__.':'.__LINE."nb_t".$p_item." n'est pas defini !!!";
return;
/* variable for in array
pa_id array of existing pa_id
hplan double array with the pa_id (column)
val double array by row with amount
op contains sequence
p_item is used to identify what op is concerned
*/
/* for each row */
for ($i=0;$i<count($val[$p_item]);$i++) {
$idx_pa_id=0;
// foreach col PA
for ($e=0;$e<count($hplan[$p_item]);$e++)
{
if ( $idx_pa_id >= (count($pa_id)-1)) {
$idx_pa_id=0;
}
echo "p_item[$p_item] e[$e]";
echo $hplan[$p_item][$e];
if ($hplan[$p_item][$e] != -1 && $val[$p_item][$i] != '')
{
echo "insert";
$op=new Anc_Operation($this->db);
$op->po_id=$hplan[$p_item][$e];
$op->pa_id=$pa_id[$idx_pa_id];
$op->oa_group=$this->oa_group;
$op->j_id=$j_id;
$op->oa_amount=$val[$p_item][$i];
$op->oa_debit=$this->oa_debit;
$op->oa_date=$this->oa_date;
$op->oa_description=$this->oa_description;
$op->oa_row=$i;
$op->add();
}
$idx_pa_id++;
}
}
$max=${"nb_t".$p_item};
// get all the PA
$plan=new Anc_Plan($this->db);
$cplan=$plan->count();
// foreach row
for ($i=1;$i<=$max;$i++) {
// foreach col PA
for ($e=1;$e<=$cplan+1;$e++)
{
if ( isset(${"ta_".$p_item."o".$e."row_".$i}) && ${"ta_".$p_item."o".$e."row_".$i}!=-1)
{
$op=new Anc_Operation($this->db);
$val=${"ta_".$p_item."o".$e."row_".$i};
list($op->pa_id,$op->po_id)=sscanf($val,"%d_%d");
$op->oa_group=$this->oa_group;
$op->j_id=$this->j_id;
$op->oa_amount=${"val".$p_item."l".$i};
$op->oa_debit=$this->oa_debit;
$op->oa_date=$this->oa_date;
$op->oa_description=$this->oa_description;
$op->oa_row=$i;
$op->add();
}
}
}
}
/*\brief transform a array of operation into a array usage by
*display_form_plan & save_form_plan
*\param $p_array array of operation
@ -517,35 +521,30 @@ function get_balance($p_from,$p_to,$p_plan_id)
*\return an array complying with \see save_form_plan
*/
function to_request ($p_array,$p_line){
if ( count($p_array) == 0 ) {
return null;
}
var_dump($p_array);
$result=array();
$table="nb_t".$p_line;
$result[]=array('op'=>$this->j_id);
$pa_id=array();
$col=1;
$line=1;
$first=true;
$last_pa_id=0;
foreach ( $p_array as $row) {
$val="val".$p_line."l".$row->oa_row;
$result[$val]=$row->oa_amount;
if ( $first ) {
$first_pa_id=$row->pa_id;
$first=false;
}
if ( $first_pa_id != $row->pa_id )
$col++;
else {
$col=1;
$line++;
}
$po="ta_".$p_line."o".$col."row_".$row->oa_row;
$result[$po]=$row->pa_id."_".$row->po_id;
// $last_pa_id=$row->pa_id;
/* First add the pa_id */
for ($i=0;$i < count($p_array);$i++){
if ( in_array($p_array[$i]->pa_id,$pa_id)==false)
$pa_id[]=$p_array[$i]->pa_id;
}
$result[$table]=$line-1;
$result['pa_id']=$pa_id;
/* add the hplan */
$seq=0;
for ($i=0;$i < count($p_array);$i++){
$hplan[$p_line][$i]=$p_array[$i]->po_id;
}
$result['hplan']=$hplan;
/* Add the amount */
$idx_pa=0;
for ($i=0;$i < count($p_array);$i++){
$val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
}
$result['val']=$val;
return $result;
}
/*!
@ -561,14 +560,13 @@ function get_balance($p_from,$p_to,$p_plan_id)
/*\brief Display a table with analytic accounting in
* detail of operation
*@note $this->j_id must be set
*\param $p_own object own
*\param $p_mode 0 = readonly or 1=writable
*\param $p_amount amount
*\param $p_id unique id
*@see display_form_plan
*\return string to display
*/
function display_table($p_own,$p_mode,$p_amount,$p_id) {
function display_table($p_mode,$p_amount,$p_id) {
static $seq=0;
$seq++;
@ -582,17 +580,23 @@ function get_balance($p_from,$p_to,$p_plan_id)
return "";
}
///////////////////////////////////////////////////////////////////////////
// TEST
///////////////////////////////////////////////////////////////////////////
/*\brief test the class
*\param
*\param
*\return
*/
function test_me() {
$array=$this->get_by_jid(442);
$a=$this->to_request($array,1);
$cn=new Database(dossier::id());
$anco=new Anc_Operation($cn);
$anco->j_id=141;
$array=$anco->get_by_jid(141);
$a=$anco->to_request($array,1);
echo $anco->display_table(1,15002,0);
var_dump($a);
}

View file

@ -180,6 +180,22 @@ class Anc_Plan
return ($a==0)?false:true;
}
/**
*@brief return an HTML string containing hidden input type to
* hold the differant PA_ID
*@param $p_array contains a array, it is the result of the fct
* Anc_Plan::get_list
*@return html string
*@see Anc_Plan::get_list
*/
static function hidden($p_array) {
var_dump($p_array);
$r='';
for ($i_anc=0;$i_anc <count($p_array);$i_anc++){
$r.=HtmlInput::hidden('pa_id[]',$p_array[$i_anc]['id']);
}
return $r;
}
static function test_me() {
$cn=new Database(dossier::id());

View file

@ -23,3 +23,9 @@ TODO9 - dépend de TODO4 TODO2 - dans impressions, on peut avoir les détails de
TODO10 Enlever le bouton enlever dans les listes d'opération et le mettre dans le DIV HTML qui présente les détails de l'op
TODO11 Ajoutez aux classes Ledger_* une fonction pour obtenir un tableau vide qui répresente le tableau utilisé par confirm, insert et veriffy
TODO12 Pour les anouveaux, les mêmes comptes se retrouvent au crédit ET au débit, il faudrait en avoir la soustraction !!
TODO13 Bouton validate CA ne fonctionne plus
TODO14 confirmation quand effacement d'un PA (comptabilité analytique -> Plan Analytique)