[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpcompta-dev] r414 - in trunk/rapport_avance: include include/template
From: |
phpcompta-dev |
Subject: |
[Phpcompta-dev] r414 - in trunk/rapport_avance: include include/template sql |
Date: |
Fri, 28 Sep 2012 23:47:18 +0200 (CEST) |
Author: danydb
Date: 2012-09-28 23:47:16 +0200 (Fri, 28 Sep 2012)
New Revision: 414
Added:
trunk/rapport_avance/include/template/declaration_display.php
Modified:
trunk/rapport_avance/include/class_formulaire_param.php
trunk/rapport_avance/include/class_rapav_declaration.php
trunk/rapport_avance/include/class_rapport_avance_sql.php
trunk/rapport_avance/include/declaration.inc.php
trunk/rapport_avance/sql/create.sql
Log:
Rapport avance : calcul de la d?\195?\169claration, modification et sauvegarde
Modified: trunk/rapport_avance/include/class_formulaire_param.php
===================================================================
--- trunk/rapport_avance/include/class_formulaire_param.php 2012-09-27
22:13:03 UTC (rev 413)
+++ trunk/rapport_avance/include/class_formulaire_param.php 2012-09-28
21:47:16 UTC (rev 414)
@@ -23,15 +23,22 @@
/**
* @file
- * @brief factory
+ * @brief factory display the definition and parameters of a form
*
*/
require_once 'class_rapport_avance_sql.php';
require_once 'class_formulaire_param_detail.php';
+/**
+ * @brief manage the table rapport_avance.formulaire_param
+ */
class Formulaire_Param extends Formulaire_Param_Sql
{
-
+ /**
+ * Factory, create an object following the $form->p_type,
+ * @param Formulaire_Param_Sql $form
+ * @return
\Formulaire_Title1|\Formulaire_Title2|\Formulaire_Title3|\Formulaire_Formula
+ */
static function factory(Formulaire_Param_Sql $form)
{
switch ($form->p_type)
@@ -48,7 +55,9 @@
}
}
-
+/**
+ * @brief mother class of
\Formulaire_Title1|\Formulaire_Title2|\Formulaire_Title3|\Formulaire_Formula
+ */
class Formulaire_Row
{
@@ -81,7 +90,9 @@
}
}
-
+/**
+ * @brief display title level 1
+ */
class formulaire_title1 extends Formulaire_Row
{
@@ -97,6 +108,9 @@
}
}
+/**
+ * @brief display title level 2
+ */
class formulaire_title2 extends Formulaire_Row
{
@@ -113,6 +127,9 @@
}
}
+/**
+ * @brief display title level 3
+ */
class formulaire_title3 extends Formulaire_Row
{
@@ -129,6 +146,10 @@
}
}
+/**
+ * @brief display the formula : depending of the type of formula, a factory is
used and an object RAPAV_Formula, RAPAV_Account_TVA
+ * or RAPAV_compute will be used for the display of the details
+ */
class Formulaire_Formula extends Formulaire_Row
{
@@ -144,7 +165,12 @@
{
echo $this->obj->p_libelle;
}
-
+ /**
+ * @brief return an object following the key type_detail of the array
passed in parameter
+ *
+ * @param type $p_index
+ * @return \RAPAV_Formula|\RAPAV_Account_Tva|\RAPAV_Compute
+ */
function make_object($p_index)
{
$elt=$this->parametre[$p_index]['type_detail'];
@@ -161,7 +187,9 @@
break;
}
}
-
+ /**
+ * @brief input value
+ */
function input()
{
echo '<h4 class="title">' . $this->obj->p_libelle . "(" .
$this->obj->p_code . ")" . '</h4>';
Modified: trunk/rapport_avance/include/class_rapav_declaration.php
===================================================================
--- trunk/rapport_avance/include/class_rapav_declaration.php 2012-09-27
22:13:03 UTC (rev 413)
+++ trunk/rapport_avance/include/class_rapav_declaration.php 2012-09-28
21:47:16 UTC (rev 414)
@@ -30,6 +30,7 @@
require_once 'class_rapav_formulaire.php';
require_once 'class_formulaire_param_detail.php';
require_once 'class_rapport_avance_sql.php';
+
/**
* @brief compute, save and display a declaration
*/
@@ -38,10 +39,11 @@
function __construct()
{
- $this->form=new RAPAV_Formulaire();
+ $this->form = new RAPAV_Formulaire();
parent::__construct();
}
- function compute($p_id,$p_start, $p_end)
+
+ function compute($p_id, $p_start, $p_end)
{
global $cn;
$cn->start();
@@ -49,94 +51,120 @@
// create object_rapav_declaration
// compute
// save the parameter
- $this->form->f_id=$p_id;
+ $this->form->f_id = $p_id;
$this->form->load();
- $this->d_title=$this->form->f_title;
- $this->d_start=$p_start;
- $this->d_end=$p_end;
- $this->to_keep='N';
+ $this->d_title = $this->form->f_title;
+ $this->d_start = $p_start;
+ $this->d_end = $p_end;
+ $this->to_keep = 'N';
$this->insert();
/*
- * First we compute the formula and tva_code
+ * First we compute the formula and tva_code for each detail
*/
- $array = $cn->get_array("select
fp.p_id,p_code,p_libelle,p_type,p_order,f_id,p_info,t_id
- from rapport_advanced.formulaire_param as fp
- join rapport_advanced.formulaire_param_detail as fpd
on (fp.p_id=fpd.p_id)
+ $array = $cn->get_array("select
p_id,p_code,p_libelle,p_type,p_order,f_id,p_info,t_id
+ from rapport_advanced.formulaire_param
where
f_id=$1
- and type_detail in (1,2)",
- array($p_id));
+ and p_type =3
+ order by p_order", array($p_id));
for ($i = 0; $i < count($array); $i++)
{
$row = new Rapav_Declaration_Param();
- $row->d_id=$this->d_id;
-
$row->dr_id=$cn->get_next_seq('rapport_advanced.declaration_param_seq');
+ $row->d_id = $this->d_id;
+ $row->dr_id =
$cn->get_next_seq('rapport_advanced.declaration_param_seq');
$row->from_array($array[$i]);
$row->compute($p_start, $p_end);
$row->insert();
}
- /*
- * Secundo we compute the compute code
- */
- $array = $cn->get_array("select
fp.p_id,p_code,p_libelle,p_type,p_order,f_id,p_info,t_id
- from rapport_advanced.formulaire_param as fp
- join rapport_advanced.formulaire_param_detail as fpd
on (fp.p_id=fpd.p_id)
- where
- f_id=$1
- and type_detail =3
- order by p_order",
- array($p_id));
+
/**
- * @note order is important !!!
- *
+ * Add the lines missing lines
*/
- for ($e = 0; $e < count($array); $e++)
- {
- $row = new Rapav_Declaration_Param();
- $row->d_id=$this->d_id;
-
$row->dr_id=$cn->get_next_seq('rapport_advanced.declaration_param_seq');
- $row->from_array($array[$e]);
- $row->compute($p_start, $p_end);
- $row->insert();
- }
- /**
- * Add the lines without definition
- */
$array = $cn->get_array("select
fp.p_id,p_code,p_libelle,p_type,p_order,f_id,p_info,t_id
from rapport_advanced.formulaire_param as fp
- left join rapport_advanced.formulaire_param_detail as
fpd on (fp.p_id=fpd.p_id)
where
f_id=$1
- and type_detail is null",
- array($p_id));
+ and p_type in (1,2,6)", array($p_id));
for ($i = 0; $i < count($array); $i++)
{
$row = new Rapav_Declaration_Param();
- $row->d_id=$this->d_id;
-
$row->dr_id=$cn->get_next_seq('rapport_advanced.declaration_param_seq');
+ $row->d_id = $this->d_id;
+ $row->dr_id =
$cn->get_next_seq('rapport_advanced.declaration_param_seq');
$row->from_array($array[$i]);
- $row->amount=0;
+ $row->amount = 0;
$row->insert();
}
$cn->commit();
}
+ function display()
+ {
+ global $cn;
+ $array = $cn->get_array('select * from
rapport_advanced.declaration_row where d_id=$1 order by dr_order',
array($this->d_id));
+ require_once 'template/declaration_display.php';
+ }
+
+ function save()
+ {
+ global $cn;
+ try
+ {
+ $cn->start();
+ $this->to_keep = 'Y';
+ $this->update();
+ $code = $_POST['code'];
+ $amount = $_POST['amount'];
+ for ($i = 0; $i < count($code); $i++)
+ {
+ $cn->exec_sql('update
rapport_advanced.declaration_row set dr_amount=$2 where
dr_id=$1',array($code[$i],$amount[$i]));
+ }
+ }
+ catch(Exception $e)
+ {
+ alert($e->getTraceAsString());
+ }
+ }
+
}
+/**
+ * @brief Match each row of a form, this row can have several details
+ *
+ */
class Rapav_Declaration_Param
{
+
+ /**
+ * @brief insert into rapport_advanced.formulaire_param
+ */
function insert()
{
- $data=new RAPAV_Declaration_Row_SQL();
- $data->dr_code=$this->param->p_code;
- $data->dr_libelle=$this->param->p_libelle;
- $data->dr_order=$this->param->p_order;
- $data->dr_amount=$this->amount;
- $data->d_id=$this->d_id;
- $data->dr_id=$this->dr_id;
+ $data = new RAPAV_Declaration_Row_SQL();
+ $data->dr_info=$this->param->p_info;
+ $data->dr_code = $this->param->p_code;
+ $data->dr_libelle = $this->param->p_libelle;
+ $data->dr_order = $this->param->p_order;
+ $data->dr_amount = $this->amount;
+ $data->d_id = $this->d_id;
+ $data->dr_id = $this->dr_id;
+ $data->dr_type = $this->param->p_type;
$data->insert();
}
+
+ /**
+ * @brief set the attribute param with the content of the array.
+ * keys :
+ * - 'p_id',
+ * - 'p_code',
+ * - 'p_libelle',
+ * - 'p_type',
+ * - 'p_order',
+ * - 'f_id',
+ * - 'p_info',
+ * - 't_id'
+ * @param type $p_array
+ */
function from_array($p_array)
{
$this->param = new Formulaire_Param();
@@ -155,6 +183,8 @@
* - 3 N-1
* - 4 N-2
* - 5 N-3
+ * @param $p_start requested date
+ * @param $p_end requested date
*/
function compute_date($p_start, $p_end)
{
@@ -204,34 +234,42 @@
$this->end = $per_end->last_day();
}
+ /* * *
+ * @brief compute amount of all the detail of
apport_advanced.formulaire_param
+ * @param $p_start requested start date
+ * @param $p_start requested end date
+ *
+ *
+ */
+
function compute($p_start, $p_end)
{
global $cn;
bcscale(2);
- $this->amount=0;
-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Compute first the formula and the account_tva
-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ $this->amount = 0;
+
$array = $cn->get_array("select
fp_id,p_id,tmp_val,tva_id,fp_formula,fp_signed,jrn_def_type,tt_id,type_detail
from rapport_advanced.formulaire_param_detail where
p_id=$1", array($this->param->p_id));
$this->compute_date($p_start, $p_end);
for ($e = 0; $e < count($array); $e++)
{
$row_detail =
Rapav_Declaration_Detail::factory($array[$e]);
- $row_detail->dr_id=$this->dr_id;
- $tmp_amount=$row_detail->compute($this->start,
$this->end);
- $this->amount=bcadd($tmp_amount,$this->amount);
+ $row_detail->dr_id = $this->dr_id;
+ $row_detail->d_id = $this->d_id;
+ $tmp_amount = $row_detail->compute($this->start,
$this->end);
+ $this->amount = bcadd($tmp_amount, $this->amount);
$row_detail->insert();
}
-
}
}
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Compute the detail for each row
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Rapav_Declaration_Detail extends RAPAV_Declaration_Row_Detail_SQL
{
+
/**
* @brief create an object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or
Rapav_dd_compute following the idx type_detail
* @param type $p_array
@@ -256,9 +294,10 @@
}
$ret->from_array($p_array);
- $ret->ddr_amount=0;
+ $ret->ddr_amount = 0; // cannot be null
return $ret;
}
+
/**
* @brief the p_array contains a row from formulaire_param_detail
* it will be copied into this->form.
@@ -283,6 +322,14 @@
class Rapav_dd_Formula extends Rapav_Declaration_Detail
{
+ /**
+ * compute the amount for one detail of type formula
+ * rapport_advanced.formulaire_param_detail
+ * @global type $cn database connexion
+ * @param $p_start (date) : computed start date
+ * @param $p_end (date) computed start date
+ * @return numeric amount computed
+ */
function compute($p_start, $p_end)
{
global $cn;
@@ -291,6 +338,7 @@
}
}
+
/**
* @brief handle the param_detail type Compute
* @see RAPAV_Compute
@@ -298,10 +346,40 @@
class Rapav_dd_Compute extends Rapav_Declaration_Detail
{
+ /**
+ * compute the amount for one detail
+ * rapport_advanced.formulaire_param_detail
+ * the attribute d_id and dr_id must be set before the call
+ * @global type $cn database connexion
+ * @param $p_start (date) : computed start date not used
+ * @param $p_end (date) computed start date not used
+ * @return numeric amount computed
+ */
function compute($p_start, $p_end)
{
- return 0;
+ global $cn;
+ $amount = 0;
+ bcscale(2);
+ // copy $this->form->fp_formula to a variable
+ $formula = $this->form->fp_formula;
+
+ // split the string from into smaller piece
+ preg_match_all("/\[([A-Z]*[0-9]*)*([0-9]*[A-Z]*)\]/i",
$formula, $e);
+ $tmp = $e[0];
+
+ foreach ($tmp as $piece)
+ {
+ // Find the code in the database
+ $search = str_replace('[', '', $piece);
+ $search = str_replace(']', '', $search);
+ $value = $cn->get_value('select
coalesce(sum(dr_amount),0) as value
+ from rapport_advanced.declaration_row where
d_id=$1 and dr_code=$2', array($this->d_id, $search));
+ $formula = str_replace($piece, $value, $formula);
+ }
+ eval('$amount = ' . $formula . ';');
+ //
+ return $amount;
}
}
@@ -327,7 +405,7 @@
* @param $p_end end date
* @return amount
*/
- private function compute_tva($p_start, $p_end)
+ private function compute_tva($p_start, $p_end)
{
if ($this->form->jrn_def_type == 'ACH')
{
@@ -337,9 +415,9 @@
(j_date >=
to_date($2,'DD.MM.YYYY') and j_date <= to_date($3,'DD.MM.YYYY'))
and j_poste::text like ($4)";
$amount = $this->cn->get_value($sql,
array($this->form->tva_id,
-
$p_start,
-
$p_end,
-
$this->form->tmp_val));
+ $p_start,
+ $p_end,
+ $this->form->tmp_val));
return $amount;
}
if ($this->form->jrn_def_type == 'VEN')
@@ -349,15 +427,16 @@
where qs_vat_code=$1
and (j_date >=
to_date($2,'DD.MM.YYYY') and j_date <= to_date($3,'DD.MM.YYYY'))
and j_poste::text like ($4)";
- $amount = $this->cn->get_value($sql,
array($this->form->tva_id,
-
$p_start,
-
$p_end,
-
$this->form->tmp_val));
- return $amount;
+ $amount = $this->cn->get_value($sql,
array($this->form->tva_id,
+ $p_start,
+ $p_end,
+ $this->form->tmp_val));
+ return $amount;
}
$this->errcode = 'Erreur dans le journal';
return 0;
}
+
/**
* compute the amount of account using the given tva_id in either the
ledger ACH or VEN
* following the $this->form->jrn_def_type.
@@ -378,9 +457,9 @@
where qs_vat_code=$1 and (j_date >=
to_date($2,'DD.MM.YYYY') and j_date <= to_date($3,'DD.MM.YYYY'))
and j_poste::text like ($4)";
$amount = $this->cn->get_value($sql,
array($this->form->tva_id,
-
$p_start,
-
$p_end,
-
$this->form->tmp_val));
+ $p_start,
+ $p_end,
+ $this->form->tmp_val));
return $amount;
}
if ($this->form->jrn_def_type == 'VEN')
@@ -397,6 +476,7 @@
$this->errcode = 'Erreur dans le journal';
return 0;
}
+
/**
* Compute the amount of TVA or Account, call internally private
functions
* @see Rapav_dd_Account_Tva::computa_amount
Rapav_dd_Account_Tva::compute_tva
@@ -439,4 +519,5 @@
}
}
+
?>
Modified: trunk/rapport_avance/include/class_rapport_avance_sql.php
===================================================================
--- trunk/rapport_avance/include/class_rapport_avance_sql.php 2012-09-27
22:13:03 UTC (rev 413)
+++ trunk/rapport_avance/include/class_rapport_avance_sql.php 2012-09-28
21:47:16 UTC (rev 414)
@@ -195,7 +195,9 @@
"dr_libelle"=>"dr_libelle",
"dr_order"=>"dr_order",
"dr_code"=>"dr_code",
- "dr_amount"=>"dr_amount"
+ "dr_amount"=>"dr_amount",
+ "dr_type"=>"dr_type",
+ "dr_info"=>"dr_info"
);
$this->type = array(
@@ -204,7 +206,9 @@
"dr_libelle"=>"text",
"dr_order"=>"text",
"dr_code"=>"numeric",
- "dr_amount"=>"numeric"
+ "dr_amount"=>"numeric",
+ "dr_type"=>"numeric",
+ "dr_info"=>'text'
);
Modified: trunk/rapport_avance/include/declaration.inc.php
===================================================================
--- trunk/rapport_avance/include/declaration.inc.php 2012-09-27 22:13:03 UTC
(rev 413)
+++ trunk/rapport_avance/include/declaration.inc.php 2012-09-28 21:47:16 UTC
(rev 414)
@@ -28,6 +28,22 @@
*/
require_once 'class_rapav_declaration.php';
global $cn;
+
+/*
+ * Save the date (update them)
+ */
+if ( isset($_POST['save']))
+{
+ $decl=new Rapav_Declaration();
+ $decl->d_id=$_POST['d_id'];
+ $decl->load();
+ $decl->save();
+ $decl->display();
+ exit();
+}
+/*
+ * compute and propose to modify and save
+ */
if (isset($_GET['compute']))
{
$decl=new Rapav_Declaration();
@@ -35,6 +51,11 @@
* @todo verifier date
*/
$decl->compute($_GET['p_form'],$_GET['p_start'],$_GET['p_end']);
+ echo '<form class="print" method="POST">';
+ $decl->display();
+ echo HtmlInput::submit('save','Sauver');
+ echo '</form>';
+ exit();
}
$date_start=new IDate('p_start');
$date_end=new IDate('p_end');
Added: trunk/rapport_avance/include/template/declaration_display.php
===================================================================
--- trunk/rapport_avance/include/template/declaration_display.php
(rev 0)
+++ trunk/rapport_avance/include/template/declaration_display.php
2012-09-28 21:47:16 UTC (rev 414)
@@ -0,0 +1,60 @@
+<?php
+
+/*
+ * 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 address@hidden
+
+/**
+ * @file
+ * @brief display content of a declaration
+ *
+ */
+?>
+<h1><?=$this->d_title?></h1>
+Du <?=$this->d_start?> au <?=$this->d_end?>
+<?
+ if ( empty($array) ) { echo 'Aucune donnée'; exit();}
+
+ // Create infobulle
+ echo HtmlInput::hidden('d_id',$this->d_id);
+for ($i=0;$i<count($array);$i++):
+ $row=$array[$i];
+switch($row['dr_type'])
+{
+ case 1:
+ echo '<h1 class="title">'.$row['dr_libelle'].'</h1>';
+ echo '<span class="notice">'.$row['dr_info'].'</span>';
+ break;
+ case 2:
+ echo '<h2 class="title">'.$row['dr_libelle'].'</h2>';
+ echo '<span class="notice">'.$row['dr_info'].'</span>';
+ break;
+ case 6:
+ echo '<h3 class="title">'.$row['dr_libelle'].'</h3>';
+ echo '<span class="notice">'.$row['dr_info'].'</span>';
+ break;
+ case 3:
+ $input=new INum('amount[]',$row['dr_amount']);
+ echo HtmlInput::hidden('code[]',$row['dr_id']);
+ echo '<p>'.$row['dr_code']." ".$row['dr_libelle']." =
".$input->input(). '<span class="notice">'.$row['dr_info'].'</span>'.'</p>';
+
+}
+endfor;
+?>
\ No newline at end of file
Modified: trunk/rapport_avance/sql/create.sql
===================================================================
--- trunk/rapport_avance/sql/create.sql 2012-09-27 22:13:03 UTC (rev 413)
+++ trunk/rapport_avance/sql/create.sql 2012-09-28 21:47:16 UTC (rev 414)
@@ -105,4 +105,6 @@
REFERENCES rapport_advanced.declaration_row (dr_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
);
+ALTER TABLE rapport_advanced.declaration_row ADD COLUMN dr_type integer;
+ALTER TABLE rapport_advanced.declaration_row ADD COLUMN dr_info text;
---
PhpCompta est un logiciel de comptabilité libre en ligne (full web)
Projet opensource http://www.phpcompta.eu
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpcompta-dev] r414 - in trunk/rapport_avance: include include/template sql,
phpcompta-dev <=