[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpcompta-dev] r534 - in trunk/rapport_avance: . include include/templa
From: |
phpcompta-dev |
Subject: |
[Phpcompta-dev] r534 - in trunk/rapport_avance: . include include/template sql |
Date: |
Thu, 17 Oct 2013 21:08:38 +0200 (CEST) |
Author: danydb
Date: 2013-10-17 21:08:37 +0200 (Thu, 17 Oct 2013)
New Revision: 534
Added:
trunk/rapport_avance/sql/1-ajout-col-formulaire-param-detail.sql
Modified:
trunk/rapport_avance/ajax_save_param_detail.php
trunk/rapport_avance/include/class_formulaire_param_detail.php
trunk/rapport_avance/include/class_rapav_declaration.php
trunk/rapport_avance/include/class_rapport_avance_sql.php
trunk/rapport_avance/include/template/param_detail_new.php
Log:
Ajout de journal comme filtre
Modified: trunk/rapport_avance/ajax_save_param_detail.php
===================================================================
--- trunk/rapport_avance/ajax_save_param_detail.php 2013-10-17 15:35:28 UTC
(rev 533)
+++ trunk/rapport_avance/ajax_save_param_detail.php 2013-10-17 19:08:37 UTC
(rev 534)
@@ -42,6 +42,7 @@
$acc_tva->p_id = $p_id;
$acc_tva->type_detail = 2;
$acc_tva->tt_id = $code_base;
+ $acc_tva->jrn_def_id=$p_ledger;
if ($acc_tva->verify() == 1)
{
$code = 'nok';
@@ -69,6 +70,7 @@
$acc_formula->fp_formula = $formula_new;
$acc_formula->p_id = $p_id;
$acc_formula->type_detail = 1;
+ $acc_formula->jrn_def_id=$p_ledger;
if ($acc_formula->verify() == 1)
{
$code = 'nok';
@@ -96,6 +98,7 @@
$acc_compute->fp_formula = $form_compute;
$acc_compute->p_id = $p_id;
$acc_compute->type_detail = 3;
+ $acc_compute->jrn_def_id=null;
if ($acc_compute->verify() == 1)
{
$code = 'nok';
@@ -125,6 +128,7 @@
$acc_account->p_id = $p_id;
$acc_account->type_detail = 4;
$acc_account->type_sum_account= $account_sum_type;
+ $acc_account->jrn_def_id=$p_ledger;
if ($acc_account->verify() == 1)
{
$code = 'nok';
@@ -156,6 +160,7 @@
$acc_account->p_id = $p_id;
$acc_account->type_detail = 5;
$acc_account->type_sum_account= $account_sum_type;
+ $acc_account->jrn_def_id=$p_ledger;
if ($acc_account->verify() == 1)
{
$code = 'nok';
Modified: trunk/rapport_avance/include/class_formulaire_param_detail.php
===================================================================
--- trunk/rapport_avance/include/class_formulaire_param_detail.php
2013-10-17 15:35:28 UTC (rev 533)
+++ trunk/rapport_avance/include/class_formulaire_param_detail.php
2013-10-17 19:08:37 UTC (rev 534)
@@ -32,290 +32,315 @@
class Formulaire_Param_Detail extends Formulaire_Param_Detail_SQL
{
- function input_new($p_id)
- {
- $parent = new Formulaire_Param($p_id);
- echo HtmlInput::title_box('Formule', 'param_detail_div');
- echo '<h2>'.$parent->p_code . " " . $parent->p_libelle.'</h2>';
- require_once 'template/param_detail_new.php';
- }
+ function input_new($p_id)
+ {
+ global $cn;
+ $parent = new Formulaire_Param($p_id);
+ echo HtmlInput::title_box('Formule', 'param_detail_div');
+ echo '<h2>' . $parent->p_code . " " . $parent->p_libelle . '</h2>';
+ $select = new ISelect('p_ledger');
+ $a_ledger = $cn->make_array('select jrn_def_id,jrn_def_name from
jrn_def order by 2', 1);
+ $a_ledger[0]['label'] = '-- Tous les journaux -- ';
+ $select->value = $a_ledger;
+ require_once 'template/param_detail_new.php';
+ }
+ function get_ledger_name()
+ {
+ global $cn;
+ $ledger = "";
+ if ($this->jrn_def_id == null || $this->jrn_def_id==-1)
+ {
+ $ledger = " tous les journaux";
+ } else
+ {
+ $tledger = $cn->get_value('select jrn_def_name from jrn_def where
jrn_def_id=$1', array($this->jrn_def_id));
+ $ledger.=" le journal " . $tledger;
+ }
+ return $ledger;
+ }
+
}
class RAPAV_Formula extends Formulaire_Param_Detail
{
- function display_row()
- {
- printf("Résultat de la formule %s", $this->fp_formula);
- }
+ function display_row()
+ {
+ $ledger = $this->get_ledger_name();
+ printf("Résultat de la formule %s utilisant $ledger",
$this->fp_formula);
+ }
- static function new_row()
- {
- $account = new IPoste("formula_new", "", "form_id");
- $account->size = 50;
- $account->label = _("Recherche poste");
- $account->set_attribute('gDossier', dossier::id());
- $account->set_attribute('bracket', 1);
- $account->set_attribute('no_overwrite', 1);
- $account->set_attribute('noquery', 1);
- $account->set_attribute('account', $account->id);
- echo $account->input();
- }
+ static function new_row()
+ {
+ $account = new IPoste("formula_new", "", "form_id");
+ $account->size = 50;
+ $account->label = _("Recherche poste");
+ $account->set_attribute('gDossier', dossier::id());
+ $account->set_attribute('bracket', 1);
+ $account->set_attribute('no_overwrite', 1);
+ $account->set_attribute('noquery', 1);
+ $account->set_attribute('account', $account->id);
+ echo $account->input();
+ }
- function verify()
- {
- if (Impress::check_formula($this->fp_formula)==false)
- {
- $this->errcode="Erreur dans votre formule";
- return 1;
- }
- if ( trim($this->fp_formula)=="")
- {
- $this->errcode=" Aucune formule trouvée";
- return 1;
- }
- return 0;
- }
+ function verify()
+ {
+ if (Impress::check_formula($this->fp_formula) == false)
+ {
+ $this->errcode = "Erreur dans votre formule";
+ return 1;
+ }
+ if (trim($this->fp_formula) == "")
+ {
+ $this->errcode = " Aucune formule trouvée";
+ return 1;
+ }
+ return 0;
+ }
+
}
class RAPAV_Account_Tva extends Formulaire_Param_Detail
{
- function display_row()
- {
- global $cn;
- $type_total=$cn->get_value("select tt_label from
rapport_advanced.total_type where tt_id=$1",array($this->tt_id));
- printf("Poste comptable %s avec le code tva %s (%s) dans le
journal %s [ %s ]",
- $this->tmp_val, $this->tva_id, $this->tva_id,
$this->jrn_def_type,$type_total);
- }
+ function display_row()
+ {
+ global $cn;
+ $ledger = $this->get_ledger_name();
+ $type_total = $cn->get_value("select tt_label from
rapport_advanced.total_type where tt_id=$1", array($this->tt_id));
+ printf("Poste comptable %s avec le code tva %s (%s) dans le journal de
type %s [ %s ] $ledger", $this->tmp_val, $this->tva_id, $this->tva_id,
$this->jrn_def_type, $type_total);
+ }
- static function new_row()
- {
- global $cn;
- $account = new IPoste("formtva", "", "formtva_id");
- $account->size = 20;
- $account->label = _("Recherche poste");
- $account->set_attribute('gDossier', dossier::id());
- $account->set_attribute('noquery', 1);
- $account->set_attribute('account', $account->id);
+ static function new_row()
+ {
+ global $cn;
+ $account = new IPoste("formtva", "", "formtva_id");
+ $account->size = 20;
+ $account->label = _("Recherche poste");
+ $account->set_attribute('gDossier', dossier::id());
+ $account->set_attribute('noquery', 1);
+ $account->set_attribute('account', $account->id);
- $tva = new ITva_Popup("code_tva");
- $tva->id = HtmlInput::generate_id("code_tva");
- $tva->set_attribute('gDossier', dossier::id());
+ $tva = new ITva_Popup("code_tva");
+ $tva->id = HtmlInput::generate_id("code_tva");
+ $tva->set_attribute('gDossier', dossier::id());
- // Jrn type
- $select = new ISelect('code_jrn');
- $select->value = array(
- array('value' => 'VEN', 'label' => 'journaux Vente'),
- array('value' => 'ACH', 'label' => 'journaux Achat')
- );
- echo '<table>';
- echo '<tr><td>Poste comptable</td>';
- echo td($account->input());
- echo '</tr>';
- echo td('TVA') . td($tva->input());
- echo '</tr>';
- echo td(_('Choix du type de journal ')) . td($select->input());
- // Base or VAT
- echo '</tr>';
- $code_base = new ISelect('code_base');
- $code_base->value = $cn->make_array("select tt_id,tt_label from
rapport_advanced.total_type order by 2");
- echo td("Type de total");
- echo td($code_base->input());
- echo '</tr>';
- echo '</table>';
- }
+ // Jrn type
+ $select = new ISelect('code_jrn');
+ $select->value = array(
+ array('value' => 'VEN', 'label' => 'journaux Vente'),
+ array('value' => 'ACH', 'label' => 'journaux Achat')
+ );
+ echo '<table>';
+ echo '<tr><td>Poste comptable</td>';
+ echo td($account->input());
+ echo '</tr>';
+ echo td('TVA') . td($tva->input());
+ echo '</tr>';
+ echo td(_('Choix du type de journal ')) . td($select->input());
+ // Base or VAT
+ echo '</tr>';
+ $code_base = new ISelect('code_base');
+ $code_base->value = $cn->make_array("select tt_id,tt_label from
rapport_advanced.total_type order by 2");
+ echo td("Type de total");
+ echo td($code_base->input());
+ echo '</tr>';
+ echo '</table>';
+ }
- function verify()
- {
- global $cn;
- if (trim($this->tmp_val) == "")
- {
- $this->errcode = 'Poste comptable est vide';
- return 1;
- }
- $count = $cn->get_value("select count(*) from tva_rate where
tva_id=$1", array($this->tva_id));
- if ($count == 0)
- {
- $this->errcode = 'Code TVA inexistant';
- return 1;
- }
- }
+ function verify()
+ {
+ global $cn;
+ if (trim($this->tmp_val) == "")
+ {
+ $this->errcode = 'Poste comptable est vide';
+ return 1;
+ }
+ $count = $cn->get_value("select count(*) from tva_rate where
tva_id=$1", array($this->tva_id));
+ if ($count == 0)
+ {
+ $this->errcode = 'Code TVA inexistant';
+ return 1;
+ }
+ }
}
class RAPAV_Compute extends Formulaire_Param_Detail
{
- function display_row()
- {
- printf("Total des codes du formulaire %s", $this->fp_formula);
- }
+ function display_row()
+ {
+ printf("Total des codes du formulaire %s", $this->fp_formula);
+ }
- static function new_row($p_id)
- {
- global $cn;
- $f_id = $cn->get_value("select f_id from
rapport_advanced.formulaire_param where p_id=$1", array($p_id));
- $account = new IText("form_compute");
- $account->size = 50;
- echo $account->input();
- echo HtmlInput::button('rapav_search_code_bt', 'Cherche codes',
sprintf(" onclick=\"rapav_search_code('%s','%s','%s','%s')\"", $_REQUEST['ac'],
$_REQUEST['plugin_code'], $_REQUEST['gDossier'], $f_id));
- }
- function verify()
- {
+ static function new_row($p_id)
+ {
+ global $cn;
+ $f_id = $cn->get_value("select f_id from
rapport_advanced.formulaire_param where p_id=$1", array($p_id));
+ $account = new IText("form_compute");
+ $account->size = 50;
+ echo $account->input();
+ echo HtmlInput::button('rapav_search_code_bt', 'Cherche codes',
sprintf(" onclick=\"rapav_search_code('%s','%s','%s','%s')\"", $_REQUEST['ac'],
$_REQUEST['plugin_code'], $_REQUEST['gDossier'], $f_id));
+ }
- if ( trim($this->fp_formula)=="")
- {
- $this->errcode=" Aucune formule trouvée";
- return 1;
- }
+ function verify()
+ {
- // copy $this->form->fp_formula to a variable
- $formula = $this->fp_formula;
+ if (trim($this->fp_formula) == "")
+ {
+ $this->errcode = " Aucune formule trouvée";
+ return 1;
+ }
- // remove the valid
- preg_match_all("/\[([A-Z]*[0-9]*)*([0-9]*[A-Z]*)\]/i",
$formula, $e);
- $formula=preg_replace("/\[([A-Z]*[0-9]*)*([0-9]*[A-Z]*)\]/i",
'',$formula);
-
$formula=preg_replace('/([0-9]+.{0,1}[0.9]*)*(\+|-|\*|\/)*/','',$formula);
- $formula=preg_replace('/(\(|\))/','',$formula);
- $formula=preg_replace('/\s/','',$formula);
+ // copy $this->form->fp_formula to a variable
+ $formula = $this->fp_formula;
- // if something remains it should be a mistake
- if ($formula != '')
- {
- $this->errcode=" Erreur dans la formule ".$formula;
- return 1;
- }
- return 0;
- }
+ // remove the valid
+ preg_match_all("/\[([A-Z]*[0-9]*)*([0-9]*[A-Z]*)\]/i", $formula, $e);
+ $formula = preg_replace("/\[([A-Z]*[0-9]*)*([0-9]*[A-Z]*)\]/i", '',
$formula);
+ $formula = preg_replace('/([0-9]+.{0,1}[0.9]*)*(\+|-|\*|\/)*/', '',
$formula);
+ $formula = preg_replace('/(\(|\))/', '', $formula);
+ $formula = preg_replace('/\s/', '', $formula);
+ // if something remains it should be a mistake
+ if ($formula != '')
+ {
+ $this->errcode = " Erreur dans la formule " . $formula;
+ return 1;
+ }
+ return 0;
+ }
+
}
+
/**
- address@hidden poste comptable utilisé avec le poste comptable, choix entre
diff crédit - debit, diff débit-crédit, crédit, débit
+ * @brief poste comptable utilisé avec le poste comptable, choix entre diff
crédit - debit, diff débit-crédit, crédit, débit
*/
class RAPAV_Account extends Formulaire_Param_Detail
{
- function display_row()
- {
- global $cn;
- $total_type_account=$cn->get_value('select tt_label from
rapport_advanced.total_type_account where tt_id=$1',
- array($this->type_sum_account));
- printf("Total %s poste comptable %s utilisé avec le poste
comptable %s",
-
$total_type_account,$this->tmp_val,$this->with_tmp_val);
- }
+ function display_row()
+ {
+ global $cn;
+ $ledger = $this->get_ledger_name();
+ $total_type_account = $cn->get_value('select tt_label from
rapport_advanced.total_type_account where tt_id=$1',
array($this->type_sum_account));
+ printf("Total %s poste comptable %s utilisé avec le poste comptable %s
utilisant $ledger", $total_type_account, $this->tmp_val, $this->with_tmp_val);
+ }
- static function new_row($p_id)
- {
- global $cn;
- $sum_type=new ISelect('account_sum_type');
- $sum_type->value=$cn->make_array("select tt_id, tt_label from
rapport_advanced.total_type_account ");
+ static function new_row($p_id)
+ {
+ global $cn;
+ $sum_type = new ISelect('account_sum_type');
+ $sum_type->value = $cn->make_array("select tt_id, tt_label from
rapport_advanced.total_type_account ");
- $account = new IPoste("account_first", "", "account_first_id");
- $account->size = 10;
- $account->label = _("Recherche poste");
- $account->set_attribute('gDossier', dossier::id());
- $account->set_attribute('account', $account->id);
+ $account = new IPoste("account_first", "", "account_first_id");
+ $account->size = 10;
+ $account->label = _("Recherche poste");
+ $account->set_attribute('gDossier', dossier::id());
+ $account->set_attribute('account', $account->id);
- $account_second = new IPoste("account_second", "",
"account_second_id");
- $account_second->size = 10;
- $account_second->label = _("Recherche poste");
- $account_second->set_attribute('gDossier', dossier::id());
- $account_second->set_attribute('account', $account_second->id);
- echo '<p>';
- echo 'Calculer ';
- echo $sum_type->input();
- echo '</p>';
- echo '<p>';
- echo 'du poste comptable '.HtmlInput::infobulle(203);
- echo $account->input();
- echo '</p>';
- echo '<p>';
- echo ' utilisé avec le poste comptable
'.HtmlInput::infobulle(203);
- echo $account_second->input();
- echo '</p>';
- }
- function verify()
- {
+ $account_second = new IPoste("account_second", "",
"account_second_id");
+ $account_second->size = 10;
+ $account_second->label = _("Recherche poste");
+ $account_second->set_attribute('gDossier', dossier::id());
+ $account_second->set_attribute('account', $account_second->id);
+ echo '<p>';
+ echo 'Calculer ';
+ echo $sum_type->input();
+ echo '</p>';
+ echo '<p>';
+ echo 'du poste comptable ' . HtmlInput::infobulle(203);
+ echo $account->input();
+ echo '</p>';
+ echo '<p>';
+ echo ' utilisé avec le poste comptable ' . HtmlInput::infobulle(203);
+ echo $account_second->input();
+ echo '</p>';
+ }
- if ( trim($this->tmp_val)=="" || trim($this->with_tmp_val)=="")
- {
- $this->errcode=" Un poste comptable est manquant";
- return 1;
- }
- return 0;
- }
+ function verify()
+ {
+ if (trim($this->tmp_val) == "" || trim($this->with_tmp_val) == "")
+ {
+ $this->errcode = " Un poste comptable est manquant";
+ return 1;
+ }
+ return 0;
+ }
+
}
+
/**
- address@hidden poste comptable utilisé avec le poste comptable, choix entre
diff crédit - debit, diff débit-crédit, crédit, débit
+ * @brief poste comptable utilisé avec le poste comptable, choix entre diff
crédit - debit, diff débit-crédit, crédit, débit
*/
class RAPAV_Reconcile extends Formulaire_Param_Detail
{
- function display_row()
- {
- global $cn;
- $total_type_account=$cn->get_value('select tt_label from
rapport_advanced.total_type_account where tt_id=$1',
- array($this->type_sum_account));
- printf("Total %s poste comptable %s utilisé avec le poste
comptable %s rapprochée dans la période donnée
- avec une opération utilisant le poste comptable %s",
-
$total_type_account,$this->tmp_val,$this->with_tmp_val,$this->operation_pcm_val);
- }
+ function display_row()
+ {
+ global $cn;
+ $total_type_account = $cn->get_value('select tt_label from
rapport_advanced.total_type_account where tt_id=$1',
array($this->type_sum_account));
+ $ledger = $this->get_ledger_name();
+ printf("Total %s poste comptable %s utilisé avec le poste comptable %s
rapprochée dans la période donnée
+ avec une opération utilisant le poste comptable %s
utisant $ledger", $total_type_account, $this->tmp_val, $this->with_tmp_val,
$this->operation_pcm_val);
+ }
- static function new_row($p_id)
- {
- global $cn;
- $sum_type=new ISelect('account_sum_type');
- $sum_type->value=$cn->make_array("select tt_id, tt_label from
rapport_advanced.total_type_account ");
+ static function new_row($p_id)
+ {
+ global $cn;
+ $sum_type = new ISelect('account_sum_type');
+ $sum_type->value = $cn->make_array("select tt_id, tt_label from
rapport_advanced.total_type_account ");
- $account = new IPoste("acrec_first", "", "acrec_first_id");
- $account->size = 10;
- $account->label = _("Recherche poste");
- $account->set_attribute('gDossier', dossier::id());
- $account->set_attribute('account', $account->id);
+ $account = new IPoste("acrec_first", "", "acrec_first_id");
+ $account->size = 10;
+ $account->label = _("Recherche poste");
+ $account->set_attribute('gDossier', dossier::id());
+ $account->set_attribute('account', $account->id);
- $account_second = new IPoste("acrec_second", "",
"acrec_second_id");
- $account_second->size = 10;
- $account_second->label = _("Recherche poste");
- $account_second->set_attribute('gDossier', dossier::id());
- $account_second->set_attribute('account', $account_second->id);
+ $account_second = new IPoste("acrec_second", "", "acrec_second_id");
+ $account_second->size = 10;
+ $account_second->label = _("Recherche poste");
+ $account_second->set_attribute('gDossier', dossier::id());
+ $account_second->set_attribute('account', $account_second->id);
- $account_third = new IPoste("acrec_third", "",
"acrec_third_id");
- $account_third->size = 10;
- $account_third->label = _("Recherche poste");
- $account_third->set_attribute('gDossier', dossier::id());
- $account_third->set_attribute('account', $account_third->id);
- echo '<p>';
- echo 'Calculer ';
- echo $sum_type->input();
- echo '</p>';
- echo '<p>';
- echo 'du poste comptable '.HtmlInput::infobulle(203);
- echo $account->input();
- echo '</p>';
- echo '<p>';
- echo ' utilisé avec le poste comptable
'.HtmlInput::infobulle(203);
- echo $account_second->input();
- echo '</p>';
- echo '<p>';
- echo ' rapproché avec une opération dans la période donnée
utilisant le poste comptable '.HtmlInput::infobulle(203);
- echo $account_third->input();
+ $account_third = new IPoste("acrec_third", "", "acrec_third_id");
+ $account_third->size = 10;
+ $account_third->label = _("Recherche poste");
+ $account_third->set_attribute('gDossier', dossier::id());
+ $account_third->set_attribute('account', $account_third->id);
+ echo '<p>';
+ echo 'Calculer ';
+ echo $sum_type->input();
+ echo '</p>';
+ echo '<p>';
+ echo 'du poste comptable ' . HtmlInput::infobulle(203);
+ echo $account->input();
+ echo '</p>';
+ echo '<p>';
+ echo ' utilisé avec le poste comptable ' . HtmlInput::infobulle(203);
+ echo $account_second->input();
+ echo '</p>';
+ echo '<p>';
+ echo ' rapproché avec une opération dans la période donnée utilisant
le poste comptable ' . HtmlInput::infobulle(203);
+ echo $account_third->input();
- echo '</p>';
- }
- function verify()
- {
+ echo '</p>';
+ }
- if ( trim($this->tmp_val)=="" || trim($this->with_tmp_val)==""
||trim($this->operation_pcm_val)=='')
- {
- $this->errcode=" Un poste comptable est manquant";
- return 1;
- }
- return 0;
- }
+ function verify()
+ {
+ if (trim($this->tmp_val) == "" || trim($this->with_tmp_val) == "" ||
trim($this->operation_pcm_val) == '')
+ {
+ $this->errcode = " Un poste comptable est manquant";
+ return 1;
+ }
+ return 0;
+ }
+
}
?>
Modified: trunk/rapport_avance/include/class_rapav_declaration.php
===================================================================
--- trunk/rapport_avance/include/class_rapav_declaration.php 2013-10-17
15:35:28 UTC (rev 533)
+++ trunk/rapport_avance/include/class_rapav_declaration.php 2013-10-17
19:08:37 UTC (rev 534)
@@ -37,439 +37,448 @@
class Rapav_Declaration extends RAPAV_Declaration_SQL
{
- function __construct()
- {
- $this->form = new RAPAV_Formulaire();
- parent::__construct();
- }
- /**
- * @brief export a declaration to CSV
- * @global $cn database conx
- * @param $p_id pk of rapav_declaration
- */
- static function to_csv($p_id)
- {
- global $cn;
- $a_row=$cn->get_array('select
dr_code,dr_libelle,dr_amount,dr_start,dr_end
+ function __construct()
+ {
+ $this->form = new RAPAV_Formulaire();
+ parent::__construct();
+ }
+
+ /**
+ * @brief export a declaration to CSV
+ * @global $cn database conx
+ * @param $p_id pk of rapav_declaration
+ */
+ static function to_csv($p_id)
+ {
+ global $cn;
+ $a_row = $cn->get_array('select
dr_code,dr_libelle,dr_amount,dr_start,dr_end
from rapport_advanced.declaration_row
- where d_id=$1 order by dr_order,dr_start',array($p_id));
+ where d_id=$1 order by dr_order,dr_start',
array($p_id));
- $a_title=$cn->get_array("select d_title
+ $a_title = $cn->get_array("select d_title
,to_char(d_start,'DD.MM.YYYY') as start
,to_char(d_end,'DD.MM.YYYY') as end
from
rapport_advanced.declaration
where
- d_id=$1",array($p_id));
-
$title=$a_title[0]['d_title']."-".$a_title[0]['start']."-".$a_title[0]['end'];
- $title = mb_strtolower($title, 'UTF-8');
- $title = str_replace(array('/', '*', '<', '>', '*', '.', '+',
':', '?', '!', " ", ";"), "_", $title);
- $out = fopen("php://output", "w");
+ d_id=$1", array($p_id));
+ $title = $a_title[0]['d_title'] . "-" . $a_title[0]['start'] . "-" .
$a_title[0]['end'];
+ $title = mb_strtolower($title, 'UTF-8');
+ $title = str_replace(array('/', '*', '<', '>', '*', '.', '+', ':',
'?', '!', " ", ";"), "_", $title);
+ $out = fopen("php://output", "w");
- header('Pragma: public');
- header('Content-type: application/csv');
- header('Content-Disposition: attachment;filename="' . $title .
'.csv"', FALSE);
- fputcsv($out, $a_title[0], ";");
+ header('Pragma: public');
+ header('Content-type: application/csv');
+ header('Content-Disposition: attachment;filename="' . $title .
'.csv"', FALSE);
+ fputcsv($out, $a_title[0], ";");
- for ($i = 0; $i < count($a_row); $i++)
- {
- printf ('"%s";"%s";%s;"%s";"%s"'."\r\n",
- $a_row[$i]['dr_code'],
- $a_row[$i]['dr_libelle'],
- nb($a_row[$i]['dr_amount']),
- format_date($a_row[$i]['dr_start']),
- format_date($a_row[$i]['dr_end'])
- );
- }
- }
- function get_file_to_parse()
- {
- global $cn;
- // create a temp directory in /tmp to unpack file and to parse
it
- $dirname=tempnam($_ENV['TMP'],'rapav_');
+ for ($i = 0; $i < count($a_row); $i++)
+ {
+ printf('"%s";"%s";%s;"%s";"%s"' . "\r\n", $a_row[$i]['dr_code'],
$a_row[$i]['dr_libelle'], nb($a_row[$i]['dr_amount']),
format_date($a_row[$i]['dr_start']), format_date($a_row[$i]['dr_end'])
+ );
+ }
+ }
+ function get_file_to_parse()
+ {
+ global $cn;
+ // create a temp directory in /tmp to unpack file and to parse it
+ $dirname = tempnam($_ENV['TMP'], 'rapav_');
+
unlink($dirname);
- mkdir ($dirname);
+ mkdir($dirname);
chdir($dirname);
// Retrieve the lob and save it into $dirname
$cn->start();
- $filename=$this->d_filename;
-
$exp=$cn->lo_export($this->d_lob,$dirname.DIRECTORY_SEPARATOR.$filename);
+ $filename = $this->d_filename;
+ $exp = $cn->lo_export($this->d_lob, $dirname . DIRECTORY_SEPARATOR .
$filename);
- if ( $exp === false ) echo_warning(
__FILE__.":".__LINE__."Export NOK $filename");
+ if ($exp === false)
+ echo_warning(__FILE__ . ":" . __LINE__ . "Export NOK $filename");
- $type="n";
+ $type = "n";
// if the doc is a OOo, we need to unzip it first
// and the name of the file to change is always content.xml
- if ( strpos($this->d_mimetype,'vnd.oasis') != 0 )
+ if (strpos($this->d_mimetype, 'vnd.oasis') != 0)
{
ob_start();
- $zip = new Zip_Extended;
- if ($zip->open($filename) === TRUE) {
- $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
- $zip->close();
- } else {
- echo __FILE__.":".__LINE__."cannot unzip model
".$filename;
- }
+ $zip = new Zip_Extended;
+ if ($zip->open($filename) === TRUE)
+ {
+ $zip->extractTo($dirname . DIRECTORY_SEPARATOR);
+ $zip->close();
+ } else
+ {
+ echo __FILE__ . ":" . __LINE__ . "cannot unzip model " .
$filename;
+ }
// Remove the file we do not need anymore
unlink($filename);
ob_end_clean();
- $file_to_parse="content.xml";
- $type="OOo";
- }
- else
- $file_to_parse=$filename;
+ $file_to_parse = "content.xml";
+ $type = "OOo";
+ } else
+ $file_to_parse = $filename;
- $cn->commit();
- return array($file_to_parse,$dirname,$type);
- }
- function generate_document()
- {
- global $cn;
- if ( $this->d_filename == "") return;
+ $cn->commit();
+ return array($file_to_parse, $dirname, $type);
+ }
- list($file_to_parse,$dirname,$type)=$this->get_file_to_parse();
+ function generate_document()
+ {
+ global $cn;
+ if ($this->d_filename == "")
+ return;
- // parse the document
- $this->parse_document($dirname,$file_to_parse,$type);
+ list($file_to_parse, $dirname, $type) = $this->get_file_to_parse();
- // Add special tag
- $this->special_tag($dirname,$file_to_parse,$type);
+ // parse the document
+ $this->parse_document($dirname, $file_to_parse, $type);
- // if the doc is a OOo, we need to re-zip it
- if ($type=='OOo' )
+ // Add special tag
+ $this->special_tag($dirname, $file_to_parse, $type);
+
+ // if the doc is a OOo, we need to re-zip it
+ if ($type == 'OOo')
{
ob_start();
- $zip = new Zip_Extended;
+ $zip = new Zip_Extended;
$res = $zip->open($this->d_filename, ZipArchive::CREATE);
- if($res !== TRUE)
- {
- echo __FILE__.":".__LINE__."cannot recreate
zip";
- exit;
- }
- $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
- $zip->close();
+ if ($res !== TRUE)
+ {
+ echo __FILE__ . ":" . __LINE__ . "cannot recreate zip";
+ exit;
+ }
+ $zip->add_recurse_folder($dirname . DIRECTORY_SEPARATOR);
+ $zip->close();
ob_end_clean();
- $file_to_save=$this->d_filename;
+ $file_to_save = $this->d_filename;
+ } else
+ {
+ $file_to_save = $file_to_parse;
}
- else
- {
- $file_to_save=$file_to_parse;
- }
- $this->load_document($dirname.DIRECTORY_SEPARATOR.$file_to_save);
- }
- function parse_document($p_dir,$p_filename,$p_type)
- {
- global $cn;
- // Retrieve all the code + amount
- if ($p_type == "OOo") {
- $array=$cn->get_array("select
'<<'||dr_code||'>>' as code,dr_amount from
rapport_advanced.declaration_row where d_id=$1 and
dr_type=3",array($this->d_id));
- }
- else {
- $array=$cn->get_array("select '<<'||dr_code||'>>' as
code,dr_amount from rapport_advanced.declaration_row where d_id=$1 and
dr_type=3",array($this->d_id));
- }
+ $this->load_document($dirname . DIRECTORY_SEPARATOR . $file_to_save);
+ }
- // open the files
- $ifile=fopen($p_dir.'/'.$p_filename,'r');
+ function parse_document($p_dir, $p_filename, $p_type)
+ {
+ global $cn;
+ // Retrieve all the code + amount
+ if ($p_type == "OOo")
+ {
+ $array = $cn->get_array("select '<<'||dr_code||'>>' as
code,dr_amount from rapport_advanced.declaration_row where d_id=$1 and
dr_type=3", array($this->d_id));
+ } else
+ {
+ $array = $cn->get_array("select '<<'||dr_code||'>>' as
code,dr_amount from rapport_advanced.declaration_row where d_id=$1 and
dr_type=3", array($this->d_id));
+ }
- // check if tmpdir exist otherwise create it
- $temp_dir=$_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR.'tmp';
- if ( is_dir($temp_dir) == false )
- {
- if ( mkdir($temp_dir) == false )
- {
- echo "Ne peut pas créer le répertoire
".$temp_dir;
- exit();
- }
- }
- // Compute output_name
- $oname=tempnam($temp_dir,"rapport_avance_");
- $ofile=fopen($oname,"w+");
+ // open the files
+ $ifile = fopen($p_dir . '/' . $p_filename, 'r');
- // read ifile
- while (! feof ($ifile))
- {
- $buffer=fgets($ifile);
- // for each code replace in p_filename the code
surrounded by << >> by the amount (value) or < or >
- foreach ($array as $key=>$value)
- {
- if ( is_numeric($value['dr_amount']) )
- {
-
$searched='office:value-type="string"><text:p>'.$value['code'];
- $replaced='office:value-type="float"
office:value="'.$value['dr_amount'].'"><text:p>'.$value['code'];
- $buffer=str_replace($searched,
$replaced, $buffer);
- }
-
$buffer=str_replace($value['code'],$value['dr_amount'],$buffer);
- }
- // write to output
- fwrite($ofile,$buffer);
- }
+ // check if tmpdir exist otherwise create it
+ $temp_dir = $_SERVER["DOCUMENT_ROOT"] . DIRECTORY_SEPARATOR . 'tmp';
+ if (is_dir($temp_dir) == false)
+ {
+ if (mkdir($temp_dir) == false)
+ {
+ echo "Ne peut pas créer le répertoire " . $temp_dir;
+ exit();
+ }
+ }
+ // Compute output_name
+ $oname = tempnam($temp_dir, "rapport_avance_");
+ $ofile = fopen($oname, "w+");
- // copy the output to input
- fclose($ifile);
- fclose($ofile);
+ // read ifile
+ while (!feof($ifile))
+ {
+ $buffer = fgets($ifile);
+ // for each code replace in p_filename the code surrounded by <<
>> by the amount (value) or < or >
+ foreach ($array as $key => $value)
+ {
+ if (is_numeric($value['dr_amount']))
+ {
+ $searched = 'office:value-type="string"><text:p>' .
$value['code'];
+ $replaced = 'office:value-type="float" office:value="' .
$value['dr_amount'] . '"><text:p>' . $value['code'];
+ $buffer = str_replace($searched, $replaced, $buffer);
+ }
+ $buffer = str_replace($value['code'], $value['dr_amount'],
$buffer);
+ }
+ // write to output
+ fwrite($ofile, $buffer);
+ }
- if ( ($ret=copy ($oname,$p_dir.'/'.$p_filename)) == FALSE )
- {
- echo _('Ne peut pas sauver '.$oname.' vers
'.$p_dir.'/'.$p_filename.' code d\'erreur ='.$ret);
- }
- /**
- * @todo clean files
- */
- // unlink ($oname);
+ // copy the output to input
+ fclose($ifile);
+ fclose($ofile);
- }
- function special_tag($p_dir,$p_filename,$p_type)
- {
- global $cn,$g_parameter;
- // Retrieve all the code + libelle
- $array[]=array('code'=>'PERIODE_DECLARATION','value'=>
format_date($this->d_start)." - ".format_date($this->d_end));
- $array[]=array('code'=>'TITRE','value'=>$this->d_title);
-
$array[]=array('code'=>'DOSSIER','value'=>$cn->format_name($_REQUEST['gDossier'],'dos'));
- $array[]=array('code'=>'NAME','value'=>$g_parameter->MY_NAME);
-
$array[]=array('code'=>'STREET','value'=>$g_parameter->MY_STREET);
-
$array[]=array('code'=>'NUMBER','value'=>$g_parameter->MY_NUMBER);
-
$array[]=array('code'=>'LOCALITE','value'=>$g_parameter->MY_COMMUNE);
-
$array[]=array('code'=>'COUNTRY','value'=>$g_parameter->MY_PAYS);
- $array[]=array('code'=>'PHONE','value'=>$g_parameter->MY_TEL);
- $array[]=array('code'=>'CEDEX','value'=>$g_parameter->MY_CP);
- $array[]=array('code'=>'FAX','value'=>$g_parameter->MY_FAX);
- $array[]=array('code'=>'NOTE','value'=>$this->d_description);
+ if (($ret = copy($oname, $p_dir . '/' . $p_filename)) == FALSE)
+ {
+ echo _('Ne peut pas sauver ' . $oname . ' vers ' . $p_dir . '/' .
$p_filename . ' code d\'erreur =' . $ret);
+ }
+ /**
+ * @todo clean files
+ */
+ // unlink ($oname);
+ }
- // open the files
- $ifile=fopen($p_dir.'/'.$p_filename,'r');
+ function special_tag($p_dir, $p_filename, $p_type)
+ {
+ global $cn, $g_parameter;
+ // Retrieve all the code + libelle
+ $array[] = array('code' => 'PERIODE_DECLARATION', 'value' =>
format_date($this->d_start) . " - " . format_date($this->d_end));
+ $array[] = array('code' => 'TITRE', 'value' => $this->d_title);
+ $array[] = array('code' => 'DOSSIER', 'value' =>
$cn->format_name($_REQUEST['gDossier'], 'dos'));
+ $array[] = array('code' => 'NAME', 'value' => $g_parameter->MY_NAME);
+ $array[] = array('code' => 'STREET', 'value' =>
$g_parameter->MY_STREET);
+ $array[] = array('code' => 'NUMBER', 'value' =>
$g_parameter->MY_NUMBER);
+ $array[] = array('code' => 'LOCALITE', 'value' =>
$g_parameter->MY_COMMUNE);
+ $array[] = array('code' => 'COUNTRY', 'value' =>
$g_parameter->MY_PAYS);
+ $array[] = array('code' => 'PHONE', 'value' => $g_parameter->MY_TEL);
+ $array[] = array('code' => 'CEDEX', 'value' => $g_parameter->MY_CP);
+ $array[] = array('code' => 'FAX', 'value' => $g_parameter->MY_FAX);
+ $array[] = array('code' => 'NOTE', 'value' => $this->d_description);
- // check if tmpdir exist otherwise create it
- $temp_dir=$_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR.'tmp';
- if ( is_dir($temp_dir) == false )
- {
- if ( mkdir($temp_dir) == false )
- {
- echo "Ne peut pas créer le répertoire
".$temp_dir;
- exit();
- }
- }
- // Compute output_name
- $oname=tempnam($temp_dir,"rapport_avance_");
- $ofile=fopen($oname,"w+");
+ // open the files
+ $ifile = fopen($p_dir . '/' . $p_filename, 'r');
- // read ifile
- while (! feof ($ifile))
- {
- $buffer=fgets($ifile);
- // for each code replace in p_filename the code
surrounded by << >> by the amount (value) or < or >
- foreach ($array as $key=>$value)
- {
- if ( $p_type=='OOo')
- {
-
$replace='<<'.$value['code'].'>>';
- $fmt_value=$value['value'];
-
$fmt_value=str_replace('&','&',$fmt_value);
-
$fmt_value=str_replace('<','<',$fmt_value);
-
$fmt_value=str_replace('>','>',$fmt_value);
-
$fmt_value=str_replace('"','"',$fmt_value);
-
$fmt_value=str_replace("'",''',$fmt_value);
- } else {
- $replace='<<'.$value['code'].'>>';
- $fmt_value= $value['value'];
- }
-
$buffer=str_replace($replace,$fmt_value,$buffer);
- }
- // write to output
- fwrite($ofile,$buffer);
- }
+ // check if tmpdir exist otherwise create it
+ $temp_dir = $_SERVER["DOCUMENT_ROOT"] . DIRECTORY_SEPARATOR . 'tmp';
+ if (is_dir($temp_dir) == false)
+ {
+ if (mkdir($temp_dir) == false)
+ {
+ echo "Ne peut pas créer le répertoire " . $temp_dir;
+ exit();
+ }
+ }
+ // Compute output_name
+ $oname = tempnam($temp_dir, "rapport_avance_");
+ $ofile = fopen($oname, "w+");
- // copy the output to input
- fclose($ifile);
- fclose($ofile);
+ // read ifile
+ while (!feof($ifile))
+ {
+ $buffer = fgets($ifile);
+ // for each code replace in p_filename the code surrounded by <<
>> by the amount (value) or < or >
+ foreach ($array as $key => $value)
+ {
+ if ($p_type == 'OOo')
+ {
+ $replace = '<<' . $value['code'] . '>>';
+ $fmt_value = $value['value'];
+ $fmt_value = str_replace('&', '&', $fmt_value);
+ $fmt_value = str_replace('<', '<', $fmt_value);
+ $fmt_value = str_replace('>', '>', $fmt_value);
+ $fmt_value = str_replace('"', '"', $fmt_value);
+ $fmt_value = str_replace("'", ''', $fmt_value);
+ } else
+ {
+ $replace = '<<' . $value['code'] . '>>';
+ $fmt_value = $value['value'];
+ }
+ $buffer = str_replace($replace, $fmt_value, $buffer);
+ }
+ // write to output
+ fwrite($ofile, $buffer);
+ }
- if ( ($ret=copy ($oname,$p_dir.'/'.$p_filename)) == FALSE )
- {
- echo _('Ne peut pas sauver '.$oname.' vers
'.$p_dir.'/'.$p_filename.' code d\'erreur ='.$ret);
- }
- /**
- * @todo clean files
- */
- // unlink ($oname);
+ // copy the output to input
+ fclose($ifile);
+ fclose($ofile);
- }
- function load_document($p_file)
- {
- global $cn;
- $cn->start();
- $this->d_lob=$cn->lo_import($p_file);
- if ( $this->d_lob == false )
- {
- echo "ne peut pas importer [$p_file]";
- return 1;
- }
- $this->d_size= filesize($p_file);
- $date=date('ymd-Hi');
- $this->d_filename=$date.'-'.$this->d_filename;
- $this->update();
- $cn->commit();
+ if (($ret = copy($oname, $p_dir . '/' . $p_filename)) == FALSE)
+ {
+ echo _('Ne peut pas sauver ' . $oname . ' vers ' . $p_dir . '/' .
$p_filename . ' code d\'erreur =' . $ret);
+ }
+ /**
+ * @todo clean files
+ */
+ // unlink ($oname);
+ }
+ function load_document($p_file)
+ {
+ global $cn;
+ $cn->start();
+ $this->d_lob = $cn->lo_import($p_file);
+ if ($this->d_lob == false)
+ {
+ echo "ne peut pas importer [$p_file]";
+ return 1;
+ }
+ $this->d_size = filesize($p_file);
+ $date = date('ymd-Hi');
+ $this->d_filename = $date . '-' . $this->d_filename;
+ $this->update();
+ $cn->commit();
+ }
- }
- /**
- *
- * @global $cn $cn
- * @param type $p_id
- * @param type $p_start
- * @param type $p_end
- * @param type $p_step
- */
- function compute($p_id, $p_start, $p_end,$p_step)
- {
- global $cn;
- $cn->start();
- // Load the parameter from formulaire_param_detail
- // create object_rapav_declaration
- // compute
- // save the parameter
- $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_lob=$this->form->f_lob;
- $this->d_filename=$this->form->f_filename;
- $this->d_mimetype=$this->form->f_mimetype;
- $this->d_size=$this->form->f_size;
- $this->d_step=$p_step;
- $this->insert();
- /*
- * First we compute the formula and tva_code for each detail
- */
- $array = $cn->get_array("select
p_id,p_code,p_libelle,p_type,p_order,f_id,t_id
+ /**
+ *
+ * @global $cn $cn
+ * @param type $p_id
+ * @param type $p_start
+ * @param type $p_end
+ * @param type $p_step
+ */
+ function compute($p_id, $p_start, $p_end, $p_step)
+ {
+ global $cn;
+ $cn->start();
+ // Load the parameter from formulaire_param_detail
+ // create object_rapav_declaration
+ // compute
+ // save the parameter
+ $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_lob = $this->form->f_lob;
+ $this->d_filename = $this->form->f_filename;
+ $this->d_mimetype = $this->form->f_mimetype;
+ $this->d_size = $this->form->f_size;
+ $this->d_step = $p_step;
+ $this->insert();
+ /*
+ * First we compute the formula and tva_code for each detail
+ */
+ $array = $cn->get_array("select
p_id,p_code,p_libelle,p_type,p_order,f_id,t_id
from rapport_advanced.formulaire_param
where
f_id=$1
order by p_order", array($p_id));
- /**
- * if step != 0, recompute the date
- */
- if ($p_step == 0)
- {
- // compute each row
- 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->from_array($array[$i]);
- if ( $array[$i]['p_type']==3) {
- $row->compute($p_start, $p_end);
- } else {
- $row->amount = 0;
- }
- $row->dr_start=$p_start;
- $row->dr_end=$p_end;
- $row->insert();
- }
- }
- else
- {
- // compute new date, stored in $this->start and
$this->end
- while ($this->compute_interval($p_start, $p_end,
$p_step) == 1)
- {
- 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->from_array($array[$i]);
- if ($array[$i]['p_type'] == 3)
- {
- $row->compute($this->start,
$this->end);
- $row->dr_start=$this->start;
- $row->dr_end=$this->end;
- $row->insert();
- }
- }
- }
+ /**
+ * if step != 0, recompute the date
+ */
+ if ($p_step == 0)
+ {
+ // compute each row
+ 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->from_array($array[$i]);
+ if ($array[$i]['p_type'] == 3)
+ {
+ $row->compute($p_start, $p_end);
+ } else
+ {
+ $row->amount = 0;
+ }
+ $row->dr_start = $p_start;
+ $row->dr_end = $p_end;
+ $row->insert();
+ }
+ } else
+ {
+ // compute new date, stored in $this->start and $this->end
+ while ($this->compute_interval($p_start, $p_end, $p_step) == 1)
+ {
+ 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->from_array($array[$i]);
+ if ($array[$i]['p_type'] == 3)
+ {
+ $row->compute($this->start, $this->end);
+ $row->dr_start = $this->start;
+ $row->dr_end = $this->end;
+ $row->insert();
+ }
+ }
+ }
+ }
+ $cn->commit();
+ }
+ function compute_interval($p_start, $p_end, $p_step)
+ {
+ static $s_start = "";
+ static $s_count = 0;
- }
- $cn->commit();
- }
- function compute_interval($p_start, $p_end, $p_step)
- {
- static $s_start = "";
- static $s_count = 0;
+ if ($s_start == "")
+ {
+ $s_start = $p_start;
+ }
+ $s_count++;
+ // initialize datetime object
+ $date_start = DateTime::createFromFormat('d.m.Y', $s_start);
+ $date_end = DateTime::createFromFormat('d.m.Y', $s_start);
+ $date_finish = DateTime::createFromFormat('d.m.Y', $p_end);
- if ($s_start == "")
- {
- $s_start = $p_start;
- }
- $s_count++;
- // initialize datetime object
- $date_start = DateTime::createFromFormat('d.m.Y',$s_start);
- $date_end = DateTime::createFromFormat('d.m.Y',$s_start);
- $date_finish = DateTime::createFromFormat('d.m.Y',$p_end);
+ $add = $this->get_interval($p_step);
- $add = $this->get_interval($p_step);
+ if ($s_count > 1)
+ {
+ $date_start->add($add);
+ $date_end->add($add);
+ }
+ // compute date_end
+ $date_end->add($add);
+ $date_end->sub(new DateInterval('P1D'));
+ // if date_end > date_finish then stop
+ if ($date_end > $date_finish)
+ return 0;
+ $this->start = $date_start->format("d.m.Y");
+ $this->end = $date_end->format("d.m.Y");
+ $s_start = $this->start;
+ return 1;
+ }
- if ($s_count > 1) { $date_start->add($add);
$date_end->add($add);}
- // compute date_end
- $date_end->add($add);
- $date_end->sub(new DateInterval('P1D'));
- // if date_end > date_finish then stop
- if ($date_end > $date_finish) return 0;
- $this->start = $date_start->format("d.m.Y");
- $this->end = $date_end->format("d.m.Y");
- $s_start = $this->start;
- return 1;
- }
- function get_interval($p_step)
- {
- $array_interval = array("", "P7D", "P14D", "P1M", "P2M", "P3M");
- return new DateInterval($array_interval[$p_step]);
- }
- function anchor_document()
- {
-
$url=HtmlInput::request_to_string(array('gDossier','ac','plugin_code'));
-
$url='extension.raw.php'.$url.'&act=export_decla_document&id='.$this->d_id;
- return HtmlInput::anchor($this->d_filename,$url);
- }
- function display()
- {
- global $cn;
- $array = $cn->get_array('select * from
rapport_advanced.declaration_row where d_id=$1 order by dr_order,dr_start',
array($this->d_id));
- require_once 'template/declaration_display.php';
- }
+ function get_interval($p_step)
+ {
+ $array_interval = array("", "P7D", "P14D", "P1M", "P2M", "P3M");
+ return new DateInterval($array_interval[$p_step]);
+ }
- 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]));
- }
- $cn->commit();
- }
- catch (Exception $e)
- {
- alert($e->getTraceAsString());
- }
- }
+ function anchor_document()
+ {
+ $url = HtmlInput::request_to_string(array('gDossier', 'ac',
'plugin_code'));
+ $url = 'extension.raw.php' . $url .
'&act=export_decla_document&id=' . $this->d_id;
+ return HtmlInput::anchor($this->d_filename, $url);
+ }
+ function display()
+ {
+ global $cn;
+ $array = $cn->get_array('select * from
rapport_advanced.declaration_row where d_id=$1 order by dr_order,dr_start',
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]));
+ }
+ $cn->commit();
+ } catch (Exception $e)
+ {
+ alert($e->getTraceAsString());
+ }
+ }
+
}
/**
@@ -479,138 +488,138 @@
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->dr_type = $this->param->p_type;
- $data->dr_start=$this->dr_start;
- $data->dr_end=$this->dr_end;
- $data->insert();
- }
+ /**
+ * @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->dr_type = $this->param->p_type;
+ $data->dr_start = $this->dr_start;
+ $data->dr_end = $this->dr_end;
+ $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',
- * - 't_id'
- * @param type $p_array
- */
- function from_array($p_array)
- {
- $this->param = new Formulaire_Param();
- foreach (array('p_id', 'p_code', 'p_libelle', 'p_type',
'p_order', 'f_id', 't_id') as $e)
- {
- $this->param->$e = $p_array[$e];
- }
- $this->param->load();
- }
+ /**
+ * @brief set the attribute param with the content of the array.
+ * keys :
+ * - 'p_id',
+ * - 'p_code',
+ * - 'p_libelle',
+ * - 'p_type',
+ * - 'p_order',
+ * - 'f_id',
+ * - 't_id'
+ * @param type $p_array
+ */
+ function from_array($p_array)
+ {
+ $this->param = new Formulaire_Param();
+ foreach (array('p_id', 'p_code', 'p_libelle', 'p_type', 'p_order',
'f_id', 't_id') as $e)
+ {
+ $this->param->$e = $p_array[$e];
+ }
+ $this->param->load();
+ }
- /**
- * @brief compute the date following the attribute t_id (match
rapport_advanced.periode_type and
- * store the result into $this->start and $this-> end
- * - 1 date from the FORM
- * - 2 N
- * - 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)
- {
- global $g_user;
- switch ($this->param->t_id)
- {
- case 1:
- $this->start = $p_start;
- $this->end = $p_end;
- return;
- break;
- case 2:
- list($this->start, $this->end) =
$g_user->get_limit_current_exercice();
- return;
- break;
- case 3:
- $exercice = $g_user->get_exercice();
- $exercice--;
- break;
- case 4:
- $exercice = $g_user->get_exercice();
- $exercice-=2;
- break;
- case 5:
- $exercice = $g_user->get_exercice();
- $exercice-=3;
- break;
- case 6:
- list($this->start, $this->end) =
$g_user->get_limit_current_exercice();
- $this->end=$p_end;
- return;
- break;
- default:
- throw new Exception('compute_date :
t_id est incorrect');
- }
- global $cn;
+ /**
+ * @brief compute the date following the attribute t_id (match
rapport_advanced.periode_type and
+ * store the result into $this->start and $this-> end
+ * - 1 date from the FORM
+ * - 2 N
+ * - 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)
+ {
+ global $g_user;
+ switch ($this->param->t_id)
+ {
+ case 1:
+ $this->start = $p_start;
+ $this->end = $p_end;
+ return;
+ break;
+ case 2:
+ list($this->start, $this->end) =
$g_user->get_limit_current_exercice();
+ return;
+ break;
+ case 3:
+ $exercice = $g_user->get_exercice();
+ $exercice--;
+ break;
+ case 4:
+ $exercice = $g_user->get_exercice();
+ $exercice-=2;
+ break;
+ case 5:
+ $exercice = $g_user->get_exercice();
+ $exercice-=3;
+ break;
+ case 6:
+ list($this->start, $this->end) =
$g_user->get_limit_current_exercice();
+ $this->end = $p_end;
+ return;
+ break;
+ default:
+ throw new Exception('compute_date : t_id est incorrect');
+ }
+ global $cn;
- // If exercice does not exist then
- // set the date end and start to 01.01.1900
+ // If exercice does not exist then
+ // set the date end and start to 01.01.1900
- $exist_exercice = $cn->get_value('select count(p_id)
from parm_periode where p_exercice=$1', array($exercice));
- if ($exist_exercice == 0)
- {
- $this->start = '01.01.1900';
- $this->end = '01.01.1900';
- return;
- }
- // Retrieve start & end date
- $periode = new Periode($cn);
- list($per_start, $per_end) =
$periode->get_limit($exercice);
- $this->start = $per_start->first_day();
- $this->end = $per_end->last_day();
- }
+ $exist_exercice = $cn->get_value('select count(p_id) from parm_periode
where p_exercice=$1', array($exercice));
+ if ($exist_exercice == 0)
+ {
+ $this->start = '01.01.1900';
+ $this->end = '01.01.1900';
+ return;
+ }
+ // Retrieve start & end date
+ $periode = new Periode($cn);
+ list($per_start, $per_end) = $periode->get_limit($exercice);
+ $this->start = $per_start->first_day();
+ $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
- *
- *
- */
+ /* * *
+ * @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";
+ function compute($p_start, $p_end)
+ {
+ global $cn;
+ bcscale(2);
+ $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,
- with_tmp_val,type_sum_account,operation_pcm_val
+ $array = $cn->get_array("select
fp_id,p_id,tmp_val,tva_id,fp_formula,fp_signed,jrn_def_type,tt_id,type_detail,
+
with_tmp_val,type_sum_account,operation_pcm_val,jrn_def_id
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;
- $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();
- }
- }
+ $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;
+ $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();
+ }
+ }
}
@@ -620,55 +629,54 @@
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
- * @return object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or
Rapav_dd_compute
- * @throws if the type is not known
- */
- static function factory($p_array)
- {
- switch ($p_array['type_detail'])
- {
- case '1':
- $ret = new Rapav_dd_Formula();
- break;
- case '2':
- $ret = new Rapav_dd_Account_Tva();
- break;
- case '3':
- $ret = new Rapav_dd_Compute();
- break;
- case '4':
- $ret = new Rapav_dd_Account();
- break;
- case '5':
- $ret = new Rapav_dd_Reconcile();
- break;
- default:
- throw new Exception("Type inconnu");
- }
+ /**
+ * @brief create an object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or
Rapav_dd_compute following the idx type_detail
+ * @param type $p_array
+ * @return object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or
Rapav_dd_compute
+ * @throws if the type is not known
+ */
+ static function factory($p_array)
+ {
+ switch ($p_array['type_detail'])
+ {
+ case '1':
+ $ret = new Rapav_dd_Formula();
+ break;
+ case '2':
+ $ret = new Rapav_dd_Account_Tva();
+ break;
+ case '3':
+ $ret = new Rapav_dd_Compute();
+ break;
+ case '4':
+ $ret = new Rapav_dd_Account();
+ break;
+ case '5':
+ $ret = new Rapav_dd_Reconcile();
+ break;
+ default:
+ throw new Exception("Type inconnu");
+ }
- $ret->from_array($p_array);
- $ret->ddr_amount = 0; // cannot be null
- return $ret;
- }
+ $ret->from_array($p_array);
+ $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.
- * @param type $p_array match formulaire_param_detail table structure
- */
- function from_array($p_array)
- {
- $this->form = new Formulaire_Param_Detail();
- $attribute = explode(',',
-
'fp_id,p_id,tmp_val,tva_id,fp_formula,fp_signed,jrn_def_type,tt_id,type_detail,with_tmp_val,type_sum_account,operation_pcm_val');
- foreach ($attribute as $e)
- {
- $this->form->$e = $p_array[$e];
- }
- }
+ /**
+ * @brief the p_array contains a row from formulaire_param_detail
+ * it will be copied into this->form.
+ * @param type $p_array match formulaire_param_detail table structure
+ */
+ function from_array($p_array)
+ {
+ $this->form = new Formulaire_Param_Detail();
+ $attribute = explode(',',
'fp_id,p_id,tmp_val,tva_id,fp_formula,fp_signed,jrn_def_type,tt_id,type_detail,with_tmp_val,type_sum_account,operation_pcm_val,jrn_def_id');
+ foreach ($attribute as $e)
+ {
+ $this->form->$e = $p_array[$e];
+ }
+ }
}
@@ -679,20 +687,20 @@
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;
- $amount = Impress::parse_formula($cn, "",
$this->form->fp_formula, $p_start, $p_end, true, 1);
- return $amount['montant'];
- }
+ /**
+ * 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;
+ $amount = Impress::parse_formula($cn, "", $this->form->fp_formula,
$p_start, $p_end, true, 1);
+ return $amount['montant'];
+ }
}
@@ -703,41 +711,41 @@
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)
- {
- global $cn;
- $amount = 0;
- bcscale(2);
+ /**
+ * 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)
+ {
+ global $cn;
+ $amount = 0;
+ bcscale(2);
- // copy $this->form->fp_formula to a variable
- $formula = $this->form->fp_formula;
+ // 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];
+ // 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
+ 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;
- }
+ $formula = str_replace($piece, $value, $formula);
+ }
+ eval('$amount = ' . $formula . ';');
+ //
+ return $amount;
+ }
}
@@ -754,128 +762,139 @@
class Rapav_dd_Account_Tva extends Rapav_Declaration_Detail
{
- /**
- * compute the amount of tva using the given account in either the
ledger ACH or VEN
- * following the $this->form->jrn_def_type.
- * set the $this->errcode if something wrong has happened
- * @param $p_start start date
- * @param $p_end end date
- * @return amount
- */
- private function compute_tva($p_start, $p_end)
- {
- if ($this->form->jrn_def_type == 'ACH')
- {
- $sql = "select coalesce(sum(qp_vat),0) as amount
+ /**
+ * compute the amount of tva using the given account in either the ledger
ACH or VEN
+ * following the $this->form->jrn_def_type.
+ * set the $this->errcode if something wrong has happened
+ * @param $p_start start date
+ * @param $p_end end date
+ * @return amount
+ */
+ private function compute_tva($p_start, $p_end)
+ {
+ $filter_ledger = "";
+ if ($this->form->jrn_def_id != "")
+ {
+ $filter_ledger = " and j_jrn_def = " .
sql_string($this->form->jrn_def_id);
+ }
+ if ($this->form->jrn_def_type == 'ACH')
+ {
+
+ $sql = "select coalesce(sum(qp_vat),0) as amount
from quant_purchase join jrnx
using (j_id)
where qp_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;
- }
- if ($this->form->jrn_def_type == 'VEN')
- {
- $sql = "select coalesce(sum(qs_vat),0) as amount
+ and j_poste::text like ($4)
$filter_ledger";
+ $amount = $this->cn->get_value($sql, array($this->form->tva_id,
+ $p_start,
+ $p_end,
+ $this->form->tmp_val));
+ return $amount;
+ }
+ if ($this->form->jrn_def_type == 'VEN')
+ {
+ $sql = "select coalesce(sum(qs_vat),0) as amount
from quant_sold join jrnx using
(j_id)
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)";
+ and j_poste::text like ($4)
$filter_ledger";
- $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;
- }
+ $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.
- * Set the $this->errcode if something wrong has happened
- * @param $p_start start date
- * @param $p_end end date
- * @return amount
- * @param type $p_start
- * @param type $p_end
- * @return \amount|int
- */
- private function compute_amount($p_start, $p_end)
- {
- if ($this->form->jrn_def_type == 'ACH')
- {
- $sql = "select coalesce(sum(qp_price),0) as amount from
quant_purchase join jrnx using (j_id)
+ /**
+ * compute the amount of account using the given tva_id in either the
ledger ACH or VEN
+ * following the $this->form->jrn_def_type.
+ * Set the $this->errcode if something wrong has happened
+ * @param $p_start start date
+ * @param $p_end end date
+ * @return amount
+ * @param type $p_start
+ * @param type $p_end
+ * @return \amount|int
+ */
+ private function compute_amount($p_start, $p_end)
+ {
+ $filter_ledger = "";
+ if ($this->form->jrn_def_id != "")
+ {
+ $filter_ledger = " and j_jrn_def = " .
sql_string($this->form->jrn_def_id);
+ }
+ if ($this->form->jrn_def_type == 'ACH')
+ {
+ $sql = "select coalesce(sum(qp_price),0) as amount from
quant_purchase join jrnx using (j_id)
where qp_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)";
+ and j_poste::text like ($4)
$filter_ledger";
- $amount = $this->cn->get_value($sql,
array($this->form->tva_id,
- $p_start,
- $p_end,
- $this->form->tmp_val));
- return $amount;
- }
- if ($this->form->jrn_def_type == 'VEN')
- {
- $sql = "select coalesce(sum(qs_price),0) as amount from
quant_sold
+ $amount = $this->cn->get_value($sql, array($this->form->tva_id,
+ $p_start,
+ $p_end,
+ $this->form->tmp_val));
+ return $amount;
+ }
+ if ($this->form->jrn_def_type == 'VEN')
+ {
+ $sql = "select coalesce(sum(qs_price),0) as amount from quant_sold
join jrnx using (j_id)
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;
- }
- $this->errcode = 'Erreur dans le journal';
- return 0;
- }
+ and j_poste::text like ($4)
$filter_ledger";
+ $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 TVA or Account, call internally private
functions
- * @see Rapav_dd_Account_Tva::computa_amount
Rapav_dd_Account_Tva::compute_tva
- * @param $p_start start date
- * @param $p_end end date
- * @return amount computed
- * @throws Exception
- */
- function compute($p_start, $p_end)
- {
- bcscale(2);
- // Retrieve the account for the tva_id, we need the DEB for VEN
and CRED for ACH
- //
+ /**
+ * Compute the amount of TVA or Account, call internally private functions
+ * @see Rapav_dd_Account_Tva::computa_amount
Rapav_dd_Account_Tva::compute_tva
+ * @param $p_start start date
+ * @param $p_end end date
+ * @return amount computed
+ * @throws Exception
+ */
+ function compute($p_start, $p_end)
+ {
+ bcscale(2);
+ // Retrieve the account for the tva_id, we need the DEB for VEN and
CRED for ACH
+ //
// tt_id gives the type of total
- // - 0 TVA + Account
- // - 1 TVA
- // - 2 Account
- switch ($this->form->tt_id)
- {
- case 0:
- $t1_amount = $this->compute_amount($p_start,
$p_end);
- $t2_amount = $this->compute_tva($p_start,
$p_end);
- $amount = bcadd($t1_amount, $t2_amount);
- break;
- case 1:
- $amount = $this->compute_tva($p_start, $p_end);
- $amount = bcadd($amount, 0);
- break;
+ // - 0 TVA + Account
+ // - 1 TVA
+ // - 2 Account
+ switch ($this->form->tt_id)
+ {
+ case 0:
+ $t1_amount = $this->compute_amount($p_start, $p_end);
+ $t2_amount = $this->compute_tva($p_start, $p_end);
+ $amount = bcadd($t1_amount, $t2_amount);
+ break;
+ case 1:
+ $amount = $this->compute_tva($p_start, $p_end);
+ $amount = bcadd($amount, 0);
+ break;
- case 2:
- $amount = $this->compute_amount($p_start,
$p_end);
- $amount = bcadd($amount, 0);
- break;
+ case 2:
+ $amount = $this->compute_amount($p_start, $p_end);
+ $amount = bcadd($amount, 0);
+ break;
- default:
- throw new Exception('Type de total invalide');
- break;
- }
- return $amount;
- }
+ default:
+ throw new Exception('Type de total invalide');
+ break;
+ }
+ return $amount;
+ }
}
@@ -892,101 +911,112 @@
class Rapav_dd_Account extends Rapav_Declaration_Detail
{
- function compute($p_start, $p_end)
- {
- global $cn;
- bcscale(2);
- switch ($this->form->type_sum_account)
- {
- // Saldo
- case 1:
- case 2:
- // Compute D-C
- $sql = "
- select sum(jrnx_amount)
- from (
- select distinct
jrn1.j_id,case when jrn1.j_debit = 't' then jrn1.j_montant else
jrn1.j_montant*(-1) end as jrnx_amount
- from jrnx as jrn1
- join jrnx as jrn2 on
(jrn1.j_grpt=jrn2.j_grpt)
- where
- jrn1.j_poste like $1
- and
- jrn2.j_poste like $2
- and (jrn1.j_date >=
to_date($3,'DD.MM.YYYY') and jrn1.j_date <= to_date($4,'DD.MM.YYYY'))
- ) as tv_amount
+ function compute($p_start, $p_end)
+ {
+ global $cn;
+ $filter_ledger = "";
+ if ($this->form->jrn_def_id != "")
+ {
+ $filter_ledger = " and jrn1.j_jrn_def = " .
sql_string($this->form->jrn_def_id);
+ }
+ bcscale(2);
+ switch ($this->form->type_sum_account)
+ {
+ // Saldo
+ case 1:
+ case 2:
+ // Compute D-C
+ $sql = "
+ select sum(jrnx_amount)
+ from (
+ select distinct jrn1.j_id,case when
jrn1.j_debit = 't' then jrn1.j_montant else jrn1.j_montant*(-1) end as
jrnx_amount
+ from jrnx as jrn1
+ join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
+ where
+ jrn1.j_poste like $1
+ and
+ jrn2.j_poste like $2
+ and (jrn1.j_date >= to_date($3,'DD.MM.YYYY')
and jrn1.j_date <= to_date($4,'DD.MM.YYYY'))
+ $filter_ledger
+ ) as tv_amount
";
- $amount=$cn->get_value($sql,array(
- $this->form->tmp_val,
- $this->form->with_tmp_val,
- $p_start,
- $p_end
- ));
- // if C-D is asked then reverse the result
- if ($this->form->type_sum_account==2)
$amount=bcmul($amount,-1);
- break;
- // Only DEBIT
- case 3:
- $sql = "
- select sum(jrnx_amount)
- from (
- select distinct
jrn1.j_id,jrn1.j_montant as jrnx_amount
- from jrnx as jrn1
- join jrnx as jrn2 on
(jrn1.j_grpt=jrn2.j_grpt)
- where
- jrn1.j_poste like $1
- and
- jrn2.j_poste like $2
- and
- jrn1.j_debit='t'
- and
- (jrn1.j_date >=
to_date($3,'DD.MM.YYYY') and jrn1.j_date <= to_date($4,'DD.MM.YYYY'))
- ) as tv_amount
+ $amount = $cn->get_value($sql, array(
+ $this->form->tmp_val,
+ $this->form->with_tmp_val,
+ $p_start,
+ $p_end
+ ));
+ // if C-D is asked then reverse the result
+ if ($this->form->type_sum_account == 2)
+ $amount = bcmul($amount, -1);
+ break;
+ // Only DEBIT
+ case 3:
+ $sql = "
+ select sum(jrnx_amount)
+ from (
+ select distinct jrn1.j_id,jrn1.j_montant as
jrnx_amount
+ from jrnx as jrn1
+ join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
+ where
+ jrn1.j_poste like $1
+ and
+ jrn2.j_poste like $2
+ and
+ jrn1.j_debit='t'
+ and
+ (jrn1.j_date >= to_date($3,'DD.MM.YYYY') and
jrn1.j_date <= to_date($4,'DD.MM.YYYY'))
+ $filter_ledger
+ ) as tv_amount
";
- $amount=$cn->get_value($sql,array(
- $this->form->tmp_val,
- $this->form->with_tmp_val,
- $p_start,
- $p_end
- ));
- break;
- // Only CREDIT
- case 4:
- $sql = "
- select sum(jrnx_amount)
- from (
- select distinct
jrn1.j_id,jrn1.j_montant as jrnx_amount
- from jrnx as jrn1
- join jrnx as jrn2 on
(jrn1.j_grpt=jrn2.j_grpt)
- where
- jrn1.j_poste like $1
- and
- jrn2.j_poste like $2
- and
- jrn1.j_debit='f'
- and
- (jrn1.j_date >=
to_date($3,'DD.MM.YYYY') and jrn1.j_date <= to_date($4,'DD.MM.YYYY'))
- ) as tv_amount
+ $amount = $cn->get_value($sql, array(
+ $this->form->tmp_val,
+ $this->form->with_tmp_val,
+ $p_start,
+ $p_end
+ ));
+ break;
+ // Only CREDIT
+ case 4:
+ $sql = "
+ select sum(jrnx_amount)
+ from (
+ select distinct jrn1.j_id,jrn1.j_montant as
jrnx_amount
+ from jrnx as jrn1
+ join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
+ where
+ jrn1.j_poste like $1
+ and
+ jrn2.j_poste like $2
+ and
+ jrn1.j_debit='f'
+ and
+ (jrn1.j_date >= to_date($3,'DD.MM.YYYY') and
jrn1.j_date <= to_date($4,'DD.MM.YYYY'))
+ $filter_ledger
+ ) as tv_amount
";
- $amount=$cn->get_value($sql,array(
- $this->form->tmp_val,
- $this->form->with_tmp_val,
- $p_start,
- $p_end
- ));
- break;
+ $amount = $cn->get_value($sql, array(
+ $this->form->tmp_val,
+ $this->form->with_tmp_val,
+ $p_start,
+ $p_end
+ ));
+ break;
- default:
- if ( DEBUG) var_dump($this);
- die (__FILE__.":".__LINE__." UNKNOW SUM TYPE");
- break;
- }
- /*
- * 4 possibilities with type_sum_account
- */
- return $amount;
- }
+ default:
+ if (DEBUG)
+ var_dump($this);
+ die(__FILE__ . ":" . __LINE__ . " UNKNOW SUM TYPE");
+ break;
+ }
+ /*
+ * 4 possibilities with type_sum_account
+ */
+ return $amount;
+ }
}
+
/**
* @brief handle the param_detail type Account
* The type_sum_account gives the type of total
@@ -1000,122 +1030,133 @@
class Rapav_dd_Reconcile extends Rapav_Declaration_Detail
{
- function compute($p_start, $p_end)
- {
- global $cn;
- bcscale(2);
- switch ($this->form->type_sum_account)
- {
- // Saldo
- case 1:
- case 2:
- // Compute D-C
- $sql = "
- select
sum(tv_amount.jrnx_amount)
- from (
- select distinct
jrn1.j_id,j1.jr_id,
- case when
jrn1.j_debit = 't' then jrn1.j_montant else jrn1.j_montant*(-1) end as
jrnx_amount
- from jrnx as
jrn1
- join jrnx as
jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
- join jrn as j1
on (jrn1.j_grpt=j1.jr_grpt_id)
- where
- jrn1.j_poste
like $1
- and
jrn2.j_poste like $2
- ) as tv_amount
- join jrn_rapt as rap1
on (rap1.jr_id=tv_amount.jr_id or rap1.jra_concerned=tv_amount.jr_id)
- join (select distinct
jrn3.j_id,j2.jr_id
- from jrnx as
jrn3
- join jrn as j2
on (j2.jr_grpt_id=jrn3.j_grpt)
- where
- (jrn3.j_date >=
to_date($3,'DD.MM.YYYY') and jrn3.j_date <= to_date($4,'DD.MM.YYYY')) and
- jrn3.j_poste
like $5) as reconc on (rap1.jr_id=reconc.jr_id or
rap1.jra_concerned=reconc.jr_id)
+ function compute($p_start, $p_end)
+ {
+ global $cn;
+ bcscale(2);
+ $filter_ledger = "";
+ if ($this->form->jrn_def_id != "")
+ {
+ $filter_ledger = " and jrn1.j_jrn_def = " .
sql_string($this->form->jrn_def_id);
+ }
+ switch ($this->form->type_sum_account)
+ {
+ // Saldo
+ case 1:
+ case 2:
+ // Compute D-C
+ $sql = "
+ select sum(tv_amount.jrnx_amount)
+ from (
+ select distinct jrn1.j_id,j1.jr_id,
+ case when jrn1.j_debit = 't' then
jrn1.j_montant else jrn1.j_montant*(-1) end as jrnx_amount
+ from jrnx as jrn1
+ join jrnx as jrn2 on
(jrn1.j_grpt=jrn2.j_grpt)
+ join jrn as j1 on
(jrn1.j_grpt=j1.jr_grpt_id)
+ where
+ jrn1.j_poste like $1
+ and jrn2.j_poste like $2
+ $filter_ledger
+ ) as tv_amount
+ join jrn_rapt as rap1 on
(rap1.jr_id=tv_amount.jr_id or rap1.jra_concerned=tv_amount.jr_id)
+ join (select distinct jrn3.j_id,j2.jr_id
+ from jrnx as jrn3
+ join jrn as j2 on
(j2.jr_grpt_id=jrn3.j_grpt)
+ where
+ (jrn3.j_date >= to_date($3,'DD.MM.YYYY') and
jrn3.j_date <= to_date($4,'DD.MM.YYYY')) and
+ jrn3.j_poste like $5) as reconc on
(rap1.jr_id=reconc.jr_id or rap1.jra_concerned=reconc.jr_id)
";
- $amount=$cn->get_value($sql,array(
- $this->form->tmp_val,
- $this->form->with_tmp_val,
- $p_start,
- $p_end,
- $this->form->operation_pcm_val
- ));
- // if C-D is asked then reverse the result
- if ($this->form->type_sum_account==2)
$amount=bcmul($amount,-1);
- break;
- // Only DEBIT
- case 3:
- $sql = "
- select
sum(tv_amount.jrnx_amount)
- from (
- select distinct
jrn1.j_id,j1.jr_id,
- jrn1.j_montant
as jrnx_amount
- from jrnx as
jrn1
- join jrnx as
jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
- join jrn as j1
on (jrn1.j_grpt=j1.jr_grpt_id)
- where
- jrn1.j_poste
like $1
- and
jrn2.j_poste like $2
- and
jrn1.j_debit='t'
- ) as tv_amount
- join jrn_rapt as rap1
on (rap1.jr_id=tv_amount.jr_id or rap1.jra_concerned=tv_amount.jr_id)
- join (select distinct
jrn3.j_id,j2.jr_id
- from jrnx as
jrn3
- join jrn as j2
on (j2.jr_grpt_id=jrn3.j_grpt)
- where
- (jrn3.j_date >=
to_date($3,'DD.MM.YYYY') and jrn3.j_date <= to_date($4,'DD.MM.YYYY')) and
- jrn3.j_poste
like $5) as reconc on (rap1.jr_id=reconc.jr_id or
rap1.jra_concerned=reconc.jr_id)
+ $amount = $cn->get_value($sql, array(
+ $this->form->tmp_val,
+ $this->form->with_tmp_val,
+ $p_start,
+ $p_end,
+ $this->form->operation_pcm_val
+ ));
+ // if C-D is asked then reverse the result
+ if ($this->form->type_sum_account == 2)
+ $amount = bcmul($amount, -1);
+ break;
+ // Only DEBIT
+ case 3:
+ $sql = "
+ select sum(tv_amount.jrnx_amount)
+ from (
+ select distinct jrn1.j_id,j1.jr_id,
+ jrn1.j_montant as jrnx_amount
+ from jrnx as jrn1
+ join jrnx as jrn2 on
(jrn1.j_grpt=jrn2.j_grpt)
+ join jrn as j1 on
(jrn1.j_grpt=j1.jr_grpt_id)
+ where
+ jrn1.j_poste like $1
+ and jrn2.j_poste like $2
+ and jrn1.j_debit='t'
+ $filter_ledger
+ ) as tv_amount
+ join jrn_rapt as rap1 on
(rap1.jr_id=tv_amount.jr_id or rap1.jra_concerned=tv_amount.jr_id)
+ join (select distinct jrn3.j_id,j2.jr_id
+ from jrnx as jrn3
+ join jrn as j2 on
(j2.jr_grpt_id=jrn3.j_grpt)
+ where
+ (jrn3.j_date >= to_date($3,'DD.MM.YYYY') and
jrn3.j_date <= to_date($4,'DD.MM.YYYY')) and
+ jrn3.j_poste like $5) as reconc on
(rap1.jr_id=reconc.jr_id or rap1.jra_concerned=reconc.jr_id)
";
- $amount=$cn->get_value($sql,array(
- $this->form->tmp_val,
- $this->form->with_tmp_val,
- $p_start,
- $p_end,
- $this->form->operation_pcm_val
- ));
- break;
- // Only CREDIT
- case 4:
- $sql = "
- select sum(tv_amount.jrnx_amount)
- from (
- select distinct
jrn1.j_id,j1.jr_id,
- jrn1.j_montant
as jrnx_amount
- from jrnx as
jrn1
- join jrnx as
jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
- join jrn as j1
on (jrn1.j_grpt=j1.jr_grpt_id)
- where
- jrn1.j_poste
like $1
- and
jrn2.j_poste like $2
- and
jrn1.j_debit='f'
- ) as tv_amount
- join jrn_rapt as rap1
on (rap1.jr_id=tv_amount.jr_id or rap1.jra_concerned=tv_amount.jr_id)
- join (select distinct
jrn3.j_id,j2.jr_id
- from jrnx as
jrn3
- join jrn as j2
on (j2.jr_grpt_id=jrn3.j_grpt)
- where
- (jrn3.j_date >=
to_date($3,'DD.MM.YYYY') and jrn3.j_date <= to_date($4,'DD.MM.YYYY')) and
- jrn3.j_poste
like $5) as reconc on (rap1.jr_id=reconc.jr_id or
rap1.jra_concerned=reconc.jr_id)
+ $amount = $cn->get_value($sql, array(
+ $this->form->tmp_val,
+ $this->form->with_tmp_val,
+ $p_start,
+ $p_end,
+ $this->form->operation_pcm_val
+ ));
+ break;
+ // Only CREDIT
+ case 4:
+ $sql = "
+ select sum(tv_amount.jrnx_amount)
+ from (
+ select distinct
jrn1.j_id,j1.jr_id,
+ jrn1.j_montant as jrnx_amount
+ from jrnx as jrn1
+ join jrnx as jrn2 on
(jrn1.j_grpt=jrn2.j_grpt)
+ join jrn as j1 on
(jrn1.j_grpt=j1.jr_grpt_id)
+ where
+ jrn1.j_poste like $1
+ and jrn2.j_poste like $2
+ and jrn1.j_debit='f'
+ $filter_ledger
+ ) as tv_amount
+ join jrn_rapt as rap1 on
(rap1.jr_id=tv_amount.jr_id or rap1.jra_concerned=tv_amount.jr_id)
+ join (select distinct
jrn3.j_id,j2.jr_id
+ from jrnx as jrn3
+ join jrn as j2 on
(j2.jr_grpt_id=jrn3.j_grpt)
+ where
+ (jrn3.j_date >=
to_date($3,'DD.MM.YYYY') and jrn3.j_date <= to_date($4,'DD.MM.YYYY')) and
+ jrn3.j_poste like $5) as
reconc on (rap1.jr_id=reconc.jr_id or rap1.jra_concerned=reconc.jr_id)
";
- $amount=$cn->get_value($sql,array(
- $this->form->tmp_val,
- $this->form->with_tmp_val,
- $p_start,
- $p_end,
- $this->form->operation_pcm_val
- ));
- break;
+ $amount = $cn->get_value($sql, array(
+ $this->form->tmp_val,
+ $this->form->with_tmp_val,
+ $p_start,
+ $p_end,
+ $this->form->operation_pcm_val
+ ));
+ break;
- default:
- if ( DEBUG) var_dump($this);
- die (__FILE__.":".__LINE__." UNKNOW SUM TYPE");
- break;
- }
- /*
- * 4 possibilities with type_sum_account
- */
- return $amount;
- }
+ default:
+ if (DEBUG)
+ var_dump($this);
+ die(__FILE__ . ":" . __LINE__ . " UNKNOW SUM TYPE");
+ break;
+ }
+ /*
+ * 4 possibilities with type_sum_account
+ */
+ return $amount;
+ }
}
+
?>
Modified: trunk/rapport_avance/include/class_rapport_avance_sql.php
===================================================================
--- trunk/rapport_avance/include/class_rapport_avance_sql.php 2013-10-17
15:35:28 UTC (rev 533)
+++ trunk/rapport_avance/include/class_rapport_avance_sql.php 2013-10-17
19:08:37 UTC (rev 534)
@@ -127,7 +127,8 @@
"type_detail"=>"type_detail",
"with_tmp_val"=>"with_tmp_val",
"type_sum_account"=>"type_sum_account",
- "operation_pcm_val"=>"operation_pcm_val"
+ "operation_pcm_val"=>"operation_pcm_val",
+ "jrn_def_id"=>"jrn_def_id"
);
$this->type = array(
@@ -142,7 +143,8 @@
"type_detail"=>"numeric",
"with_tmp_val"=>"text",
"type_sum_account"=>"numeric",
- "operation_pcm_val"=>"text"
+ "operation_pcm_val"=>"text",
+ "jrn_def_id"=>"numeric"
);
Modified: trunk/rapport_avance/include/template/param_detail_new.php
===================================================================
--- trunk/rapport_avance/include/template/param_detail_new.php 2013-10-17
15:35:28 UTC (rev 533)
+++ trunk/rapport_avance/include/template/param_detail_new.php 2013-10-17
19:08:37 UTC (rev 534)
@@ -77,6 +77,7 @@
<?php echo HtmlInput::hidden('tab','formula')?>
<?php echo RAPAV_Formula::new_row()?>
</p>
+ <p> Filtrage par journal <?php echo $select->input(); ?> </p>
<?php echo HtmlInput::submit('save','Sauve')?>
</form>
@@ -90,6 +91,7 @@
<?php echo HtmlInput::hidden('tab','account_tva')?>
<?php echo RAPAV_Account_Tva::new_row()?>
+ <p> Filtrage par journal <?php echo $select->input(); ?> </p>
<?php echo HtmlInput::submit('save','Sauve')?>
</form>
@@ -114,6 +116,7 @@
<?php echo HtmlInput::hidden('tab','new_account_id')?>
<?php echo RAPAV_Account::new_row($p_id)?>
+ <p> Filtrage par journal <?php echo $select->input(); ?> </p>
<?php echo HtmlInput::submit('save','Sauve')?>
</form>
@@ -125,6 +128,7 @@
<?php echo HtmlInput::hidden('tab','new_reconcile_id')?>
<?php echo RAPAV_Reconcile::new_row($p_id)?>
+ <p> Filtrage par journal <?php echo $select->input(); ?> </p>
<?php echo HtmlInput::submit('save','Sauve')?>
</form>
Added: trunk/rapport_avance/sql/1-ajout-col-formulaire-param-detail.sql
===================================================================
--- trunk/rapport_avance/sql/1-ajout-col-formulaire-param-detail.sql
(rev 0)
+++ trunk/rapport_avance/sql/1-ajout-col-formulaire-param-detail.sql
2013-10-17 19:08:37 UTC (rev 534)
@@ -0,0 +1,18 @@
+ALTER TABLE rapport_advanced.formulaire_param_detail
+ ADD COLUMN jrn_def_id bigint;
+COMMENT ON COLUMN rapport_advanced.formulaire_param_detail.jrn_def_id IS 'FK
to jrn_def, if null then all the ledgers are concerned';
+ALTER TABLE rapport_advanced.formulaire_param_detail
+ ADD CONSTRAINT formulaire_param_detail_jrn_def_id_fkey FOREIGN KEY
(jrn_def_id)
+ REFERENCES jrn_def (jrn_def_id) MATCH SIMPLE
+ ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;
+ALTER TABLE rapport_advanced.formulaire_param_detail
+ ADD CONSTRAINT formulaire_param_detail_jrn_def_id_fkey FOREIGN KEY
(jrn_def_id)
+ REFERENCES jrn_def (jrn_def_id) MATCH SIMPLE
+ ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;
+CREATE TRIGGER formulaire_param_detail_trg
+ BEFORE INSERT OR UPDATE OF jrn_def_id
+ ON rapport_advanced.formulaire_param_detail
+ FOR EACH ROW
+ EXECUTE PROCEDURE
rapport_advanced.formulaire_param_detail_jrn_def_id_ins_upd();
+
+
---
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] r534 - in trunk/rapport_avance: . include include/template sql,
phpcompta-dev <=