diff --git a/doc/manuel-fr.odt b/doc/manuel-fr.odt index 3c17a3cb0..9d4c6baf6 100644 Binary files a/doc/manuel-fr.odt and b/doc/manuel-fr.odt differ diff --git a/include/anc_imp.inc.php b/include/anc_imp.inc.php index 72f9559c7..fc3bfb071 100644 --- a/include/anc_imp.inc.php +++ b/include/anc_imp.inc.php @@ -35,7 +35,10 @@ require_once('ac_common.php'); //-- the menu $menu=array(array("?p_action=ca_imp&sub=listing&$str_dossier",_("Listing"),_("Listing des opérations"),"listing"), array("?p_action=ca_imp&sub=bs&$str_dossier",_("Balance simple"),_("Balance simple d'un plan analytique"),"bs"), - array("?p_action=ca_imp&sub=bc2&$str_dossier",_("Balance croisée"),_("Balance croisée de 2 plans analytiques"),"bc2") + array("?p_action=ca_imp&sub=bc2&$str_dossier",_("Balance croisée"),_("Balance croisée de 2 plans analytiques"),"bc2"), + array("?p_action=ca_imp&sub=tab&$str_dossier",_("Tableau"),_("Tableau lié à la comptabilité"),'tab'), + array("?p_action=ca_imp&sub=groupe&$str_dossier",_("Groupe"),_("Balance par groupe"),'gr'), + ); $sub=(isset($_GET['sub']))?$_GET['sub']:'no'; @@ -107,4 +110,22 @@ if ( $sub == 'bc2') echo $bc->display_html(); } } +//---------------------------------------------------------------------- +// Table linked between accountancy and analytic +//--------------------------------------------------------------------------- +if ( $sub == 'tab') + { + require_once('class_anc_table.php'); + $tab=new Anc_Table($cn); + $tab->get_request(); + echo '
'; + echo $tab->display_form($str_hidden); + echo '

'.HtmlInput::submit('Recherche','Recherche').'

'; + echo '
'; + if ( isset($_GET['result'])) + { + echo $tab->show_button($str_hidden); + $tab->display_html(); + } + } \ No newline at end of file diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php index 80b98ce2f..30fa7b31b 100644 --- a/include/class_acc_ledger_purchase.php +++ b/include/class_acc_ledger_purchase.php @@ -490,7 +490,8 @@ class Acc_Ledger_Purchase extends Acc_Ledger $op->oa_group=$group; $op->j_id=$j_id; $op->oa_date=$e_date; - $op->oa_debit=($amount < 0 )?'t':'f'; + echo $amount; + $op->oa_debit=($amount > 0 )?'t':'f'; $op->oa_description=FormatString($e_comm); $op->save_form_plan($_POST,$i,$j_id); } diff --git a/include/class_acc_operation.php b/include/class_acc_operation.php index 75aebf513..a869dfb47 100644 --- a/include/class_acc_operation.php +++ b/include/class_acc_operation.php @@ -87,7 +87,7 @@ class Acc_Operation function insert_jrnx() { - if ( $this->poste == "") return true; + if ( $this->poste == "") return false; /* for negative amount the operation is reversed */ if ( $this->amount < 0 ) { diff --git a/include/class_acc_reconciliation.php b/include/class_acc_reconciliation.php index 27466ea36..eabfada62 100644 --- a/include/class_acc_reconciliation.php +++ b/include/class_acc_reconciliation.php @@ -188,13 +188,7 @@ class Acc_Reconciliation } /** *@brief return array of not-reconciled operation - *@param - *@return - *@note - *@see - @code - - @endcode + */ function get_not_reconciled() { diff --git a/include/class_anc_balance_double.php b/include/class_anc_balance_double.php index d52d40fcc..16c0b1bfb 100644 --- a/include/class_anc_balance_double.php +++ b/include/class_anc_balance_double.php @@ -127,18 +127,40 @@ class Anc_Balance_Double extends Anc_Print $r.=""; $r.=h2info('Résumé'); - $r.=''; + $r.='
'; + $r.=''; + $r.=th('Po'). + th('Nom'). + th('Débit',' style="text-align:right"'). + th('Crédit','style="text-align:right" '). + th('Solde',' style="text-align:right"'); + $sum=$this->show_sum($array); + $tot_cred=0;$tot_deb=0; foreach ($sum as $row) { $r.=''; $r.=''; $r.=''; - $r.=''; - $r.=''; + $r.=''; + $r.=''; + $diff=bcsub($row['debit'],$row['credit']); + $tot_cred=bcadd($tot_cred,$row['credit']); + $tot_deb=bcadd($tot_deb,$row['debit']); + + $r.=td(nbm($diff),' class="num" '); + $r.=''; $r.=''; } + $r.=td(''); + $r.=td('total'); + $r.=td(nbm($tot_deb),'class="num"'); + $r.=td(nbm($tot_cred),'class="num"'); + $solde=bcsub($tot_deb,$tot_cred); + $sign=($tot_cred<$tot_deb)?" - ":" + "; + $r.=td($sign.nbm($solde),'class="num" style="border:solid 1px blue;font-weight:bold"'); + $r.=''; $r.='
'.$row['poste'].''.$row['desc'].''.nbm($row['debit']).''.nbm($row['credit']).''.nbm($row['debit']).''.nbm($row['credit']).''.$row['dc'].'
'; return $r; @@ -465,28 +487,7 @@ class Anc_Balance_Double extends Anc_Print } - /*! - * \brief Set the filter (account_date) - * - * \return return the string to add to load - */ - function set_sql_filter() - { - $sql=""; - $and=" and "; - if ( $this->from != "" ) - { - $sql.="$and a.oa_date >= to_date('".$this->from."','DD.MM.YYYY')"; - } - if ( $this->to != "" ) - { - $sql.=" $and a.oa_date <= to_date('".$this->to."','DD.MM.YYYY')"; - } - - return $sql; - - } /*! * \brief add extra lines with sum of each account @@ -533,8 +534,8 @@ class Anc_Balance_Double extends Anc_Print $s=abs($tot_deb-$tot_cred); $d=($tot_deb>$tot_cred)?'debit':'credit'; $array[]=array('poste'=>$old,'desc'=>$old_desc - ,'debit'=>$tot_deb,'credit'=>$tot_cred, - + ,'debit'=>$tot_deb,'credit'=>$tot_cred, + 'solde'=>$s,'dc'=>$d); diff --git a/include/class_anc_operation.php b/include/class_anc_operation.php index bf23f8fa2..8ba5167e5 100644 --- a/include/class_anc_operation.php +++ b/include/class_anc_operation.php @@ -480,7 +480,7 @@ class Anc_Operation $value=new INum(); $value->name="val[".$p_seq."][]"; $value->size=6; - $value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:$p_amount; + $value->value=abs((isset($val[$p_seq][$i]))?$val[$p_seq][$i]:$p_amount); $value->readonly=($p_mode==1)?false:true; $result.=''.$value->input().''; @@ -549,7 +549,7 @@ class Anc_Operation $op->po_id=$hplan[$p_item][$e]; $op->oa_group=$this->oa_group; $op->j_id=$j_id; - $op->oa_amount=$val[$p_item][$row]; + $op->oa_amount=abs($val[$p_item][$row]); $op->oa_debit=$this->oa_debit; $op->oa_date=$this->oa_date; diff --git a/include/class_anc_print.php b/include/class_anc_print.php index 1aff76455..607904502 100644 --- a/include/class_anc_print.php +++ b/include/class_anc_print.php @@ -118,7 +118,7 @@ class Anc_Print $r.= ''._('Les dates sont en format DD.MM.YYYY').''; $r.=$p_hidden; - $r.=''; + $r.=''; $plan=new Anc_Plan($this->db); $plan_id=new ISelect("pa_id"); $plan_id->value=$this->db->make_array("select pa_id, pa_name from plan_analytique order by pa_name"); @@ -142,4 +142,27 @@ class Anc_Print $r.=''; return $r; } + /*! + * \brief Set the filter (account_date) + * + * \return return the string to add to load + */ + + function set_sql_filter() + { + $sql=""; + $and=" and "; + if ( $this->from != "" ) + { + $sql.="$and a.oa_date >= to_date('".$this->from."','DD.MM.YYYY')"; + } + if ( $this->to != "" ) + { + $sql.=" $and a.oa_date <= to_date('".$this->to."','DD.MM.YYYY')"; + } + + return $sql; + + } + } diff --git a/include/class_anc_table.php b/include/class_anc_table.php new file mode 100644 index 000000000..ad3275a46 --- /dev/null +++ b/include/class_anc_table.php @@ -0,0 +1,242 @@ +cn=$p_cn; + } + function get_request() + { + parent::get_request(); + $this->card_poste=HtmlInput::default_value('card_poste',1,$_GET); + } + function display_form($p_hidden='') + { + $r=parent::display_form($p_hidden); + $icard=new ISelect('card_poste'); + $icard->value=array( + array('value'=>1,'label'=>'Par fiche'), + array('value'=>2,'label'=>'Par poste comptable') + ); + + $icard->selected=$this->card_poste; + $r.=$icard->input(); + return $r; + } + /** + * load the data + * does not return anything but give a value to this->aheader and this->arow + */ + function load_card() + { + $date=$this->set_sql_filter(); + $date=($date != '')?" $date":''; + $sql_from_poste=($this->from_poste!='')?" and po.po_name >= upper('".Database::escape_string($this->from_poste)."')":''; + $sql_to_poste=($this->to_poste!='')?" and po.po_name <= upper('".Database::escape_string($this->to_poste)."')":''; + + $header="select distinct po_id,po_name from v_table_analytic_card where + pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste." order by po_name"; + $this->aheader=$this->db->get_array($header,array($this->pa_id)); + + $this->arow=$this->db->get_array("select distinct f_id,j_qcode,name from v_table_analytic_card where + pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste." order by name",array($this->pa_id)); + $this->sql='select sum_amount from v_table_analytic_card where f_id=$1 and po_id=$2 and pa_id='.$this->pa_id.' '.$date.$sql_from_poste.$sql_to_poste; + } + function set_sql_filter() + { + $sql=""; + $and=" and "; + if ( $this->from != "" ) + { + $sql.="$and oa_date >= to_date('".$this->from."','DD.MM.YYYY')"; + } + if ( $this->to != "" ) + { + $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')"; + } + + return $sql; + + } + + /** + * load the data + * does not return anything but give a value to this->aheader and this->arow + */ + function load_poste() + { + $date=$this->set_sql_filter(); + $date=($date != '')?" $date":''; + $sql_from_poste=($this->from_poste!='')?" and po.po_name >= upper('".Database::escape_string($this->from_poste)."')":''; + $sql_to_poste=($this->to_poste!='')?" and po.po_name <= upper('".Database::escape_string($this->to_poste)."')":''; + + $header="select distinct po_id,po_name from v_table_analytic_account where + pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste." order by po_name"; + $this->aheader=$this->db->get_array($header,array($this->pa_id)); + + $this->arow=$this->db->get_array("select distinct j_poste,name from v_table_analytic_account where + pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste." order by j_poste",array($this->pa_id)); + $this->sql='select sum_amount from v_table_analytic_account where j_poste=$1 and po_id=$2 and pa_id='.$this->pa_id.' '.$date.$sql_from_poste.$sql_to_poste; + } + /** + *@brief display the button export CSV + *@param $p_hidden is a string containing hidden items + *@return html string + */ + function show_button($p_hidden) + { + $r=""; + $r.= '
'; + $r.= HtmlInput::hidden("act","CSV/AncTable"); + $r.= HtmlInput::hidden("to",$this->to); + $r.= HtmlInput::hidden("from",$this->from); + $r.= HtmlInput::hidden("pa_id",$this->pa_id); + $r.= HtmlInput::hidden("from_poste",$this->from_poste); + $r.= HtmlInput::hidden("to_poste",$this->to_poste); + $r.= $p_hidden; + $r.= dossier::hidden(); + $r.=HtmlInput::submit('bt_csv',"Export en CSV"); + $r.= '
'; + return $r; + } + function display_html() + { + bcscale(2); + + if ( $this->card_poste=='1') + { + $this->load_card(); + + echo ''; + echo ''; + echo th('Fiche'); + foreach ($this->aheader as $h) + { + echo ''; + } + echo th('Total',' style="text-align:right"'); + echo ''; + /* + * Show all the result + */ + $tot_global=0; + for ($i=0;$iarow);$i++) + { + echo ''; + echo td(HtmlInput::history_card($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].' '.$this->arow[$i]['name'])); + $tot_row=0; + for ($x=0;$xaheader);$x++) + { + $amount=$this->db->get_value($this->sql,array($this->arow[$i]['f_id'],$this->aheader[$x]['po_id'])); + if ($amount==null)$amount=0; + if ( isset($tot_col[$x])) + { + $tot_col[$x]=bcadd($tot_col[$x],$amount); + } + else + { + $tot_col[$x]=$amount; + } + echo td(nbm($amount),' class="num" '); + $tot_row=bcadd($tot_row,$amount); + } + echo td(nbm($tot_row),' class="num"'); + $tot_global=bcadd($tot_global,$tot_row); + echo ''; + + + } + echo ''; + echo td('Totaux'); + for ($i=0;$iaheader);$i++) + { + echo td(nbm($tot_col[$i]),' class="num"'); + } + echo td(nbm($tot_global),' class="num" style="font-size:130%;text-weight:bold;border:solid 1px blue"'); + echo ''; + echo '
'.h($h['po_name']).'
'; + } + if ( $this->card_poste=='2') + { + $this->load_poste(); + + echo ''; + echo ''; + echo th('poste comptable '); + foreach ($this->aheader as $h) + { + echo ''; + } + echo th('Total',' style="text-align:right"'); + echo ''; + /* + * Show all the result + */ + $tot_global=0; + for ($i=0;$iarow);$i++) + { + echo ''; + echo td(HtmlInput::history_account($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].' '.$this->arow[$i]['name'])); + $tot_row=0; + for ($x=0;$xaheader);$x++) + { + $amount=$this->db->get_value($this->sql,array($this->arow[$i]['j_poste'],$this->aheader[$x]['po_id'])); + if ($amount==null)$amount=0; + if ( isset($tot_col[$x])) + { + $tot_col[$x]=bcadd($tot_col[$x],$amount); + } + else + { + $tot_col[$x]=$amount; + } + echo td(nbm($amount),' class="num" '); + $tot_row=bcadd($tot_row,$amount); + } + echo td(nbm($tot_row),' class="num"'); + $tot_global=bcadd($tot_global,$tot_row); + echo ''; + + + } + echo ''; + + echo td('Totaux'); + for ($i=0;$iaheader);$i++) + { + echo td(nbm($tot_col[$i]),' class="num"'); + } + echo td(nbm($tot_global),' class="num" style="font-size:130%;text-weight:bold;border:solid 1px blue"'); + echo ''; + echo '
'.h($h['po_name']).'
'; + + } + + } +} \ No newline at end of file diff --git a/sql/upgrade.sql b/sql/upgrade.sql index f10349354..a1679b93e 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -2,4 +2,45 @@ create unique index qs_j_id on quant_sold(j_id); create unique index qp_j_id on quant_purchase(j_id); create unique index qf_jr_id on quant_fin(jr_id); update jrn_def set jrn_def_code=substr(jrn_def_code,1,1)||substr(jrn_def_code,length(jrn_def_code)-1,length(jrn_def_code)); +alter table operation_analytique drop column pa_id; +ALTER TABLE operation_analytique ADD CONSTRAINT operation_analytique_oa_amount_check CHECK (oa_amount >= 0::numeric); + +CREATE OR REPLACE VIEW v_table_analytic_card AS + SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum( + CASE + WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric + ELSE operation_analytique.oa_amount + END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value + FROM fiche_detail + WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS name + FROM operation_analytique + JOIN poste_analytique po USING (po_id) + JOIN jrnx USING (j_id) + GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value + FROM fiche_detail + WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), po.po_description + HAVING sum( +CASE + WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric + ELSE operation_analytique.oa_amount +END) <> 0::numeric; + + +CREATE OR REPLACE VIEW v_table_analytic_account AS + SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum( + CASE + WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric + ELSE operation_analytique.oa_amount + END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name + FROM operation_analytique + JOIN poste_analytique po USING (po_id) + JOIN jrnx USING (j_id) + JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text + GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, po.po_description + HAVING sum( +CASE + WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric + ELSE operation_analytique.oa_amount +END) <> 0::numeric; + commit;