[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpcompta-dev] r4615 - phpcompta/branches/rel560/include
From: |
phpcompta-dev |
Subject: |
[Phpcompta-dev] r4615 - phpcompta/branches/rel560/include |
Date: |
Fri, 16 Dec 2011 02:56:41 +0100 (CET) |
Author: danydb
Date: 2011-12-16 02:56:39 +0100 (Fri, 16 Dec 2011)
New Revision: 4615
Modified:
phpcompta/branches/rel560/include/class_acc_reconciliation.php
phpcompta/branches/rel560/include/class_lettering.php
Log:
>From 6.0 add auto lettering when reconciling
Modified: phpcompta/branches/rel560/include/class_acc_reconciliation.php
===================================================================
--- phpcompta/branches/rel560/include/class_acc_reconciliation.php
2011-12-16 01:56:02 UTC (rev 4614)
+++ phpcompta/branches/rel560/include/class_acc_reconciliation.php
2011-12-16 01:56:39 UTC (rev 4615)
@@ -23,11 +23,12 @@
/*!\file
* \brief class acc_reconciliation, this class is new and the code
* must use it
- *
+ *
*/
require_once("class_iconcerned.php");
require_once ('class_database.php');
require_once ('class_dossier.php');
+require_once 'class_lettering.php';
/*! \brief new class for managing the reconciliation it must be used
* instead of the function InsertRapt, ...
@@ -60,7 +61,7 @@
}
/*!
*\brief Insert into jrn_rapt the concerned operations
- *
+ *
* \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned or a string
* like "jr_id2,jr_id3,jr_id4..."
*
@@ -90,9 +91,9 @@
}
/*!
- *\brief Insert into jrn_rapt the concerned operations
+ *\brief Insert into jrn_rapt the concerned operations
* should not be called directly, use insert instead
- *
+ *
* \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
*
* \return none
@@ -112,22 +113,61 @@
"select jra_id from jrn_rapt where
jra_concerned=".$this->jr_id.
" and jr_id=$jr_id2
union
- select jra_id from jrn_rapt where jra_id=".$this->jr_id.
+ select jra_id from jrn_rapt where jr_id=".$this->jr_id.
" and jra_concerned=$jr_id2 ")
==0)
{
// Ok we can insert
$Res=$this->db->exec_sql("insert into
jrn_rapt(jr_id,jra_concerned) values ".
- "(".$this->jr_id.",$jr_id2)");
+ "(".$this->jr_id.",$jr_id2)");
+ // try to letter automatically same account from both
operation
+ $this->auto_letter($jr_id2);
}
return true;
}
- /*!
+ /**
+ * @brief try to letter same card between $p_jrid and $this->jr_id
+ * @param jrn.jr_id $p_jrid the operation to reconcile
+ */
+ function auto_letter($p_jrid)
+ {
+ // Try to find same card from both operation
+ $sql="select j1.f_id as fiche ,coalesce(j1.j_id,-1) as
jrnx_id1,coalesce(j2.j_id,-1) as jrnx_id2,
+j1.j_poste as poste
+ from jrnx as j1
+ join jrn as jr1 on
(j1.j_grpt=jr1.jr_grpt_id)
+ join jrnx as j2 on
(coalesce(j1.f_id,-1)=coalesce(j2.f_id,-1) and j1.j_poste=j2.j_poste)
+ join jrn as jr2 on
(j2.j_grpt=jr2.jr_grpt_id)
+ where
+ jr1.jr_id=$1
+ and
+ jr2.jr_id= $2";
+ $result=$this->db->get_array($sql,array($this->jr_id,$p_jrid));
+ if ( count($result) == 0)
+ {
+ return;
+ }
+ for ($i=0;$i<count($result);$i++)
+ {
+ if ( $result[$i]['fiche'] != -1)
+ {
+ $letter = new Lettering_Card($this->db);
+
$letter->insert_couple($result[$i]['jrnx_id1'],$result[$i]['jrnx_id2']);
+ }
+ else
+ {
+ $letter = new Lettering_Account($this->db);
+
$letter->insert_couple($result[$i]['jrnx_id1'],$result[$i]['jrnx_id2']);
+ }
+ }
+ }
+
+ /*!
*\brief Insert into jrn_rapt the concerned operations
- *
+ *
* \param $this->jr_id (jrn.jr_id) => jrn_rapt.jr_id
* \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
- *
+ *
* \return none
*/
function remove($jr_id2)
@@ -144,8 +184,29 @@
select jra_id from jrn_rapt where
jra_concerned=$jr_id2 ".
" and jr_id=".$this->jr_id) !=0)
{
- // Ok we can delete
- $Res=$this->db->exec_sql("delete from jrn_rapt where ".
+ /**
+ * remove also lettering between both operation
+ */
+ $sql = " delete from
+ jnt_letter
+ where jl_id in ( select jl_id from
jnt_letter
+
join letter_cred as lc using(jl_id)
+
join letter_deb as ld using (jl_id)
+ where
+
lc.j_id in (select j_id
+
from jrnx join jrn on (j_grpt=jr_grpt_id)
+
where jr_id in ($1,$2))
+
or
+
ld.j_id in (select j_id
+
from jrnx join jrn on (j_grpt=jr_grpt_id)
+
where jr_id in ($1,$2))
+
+
+
+ )";
+ $this->db->exec_sql($sql, array($jr_id2, $this->jr_id));
+ // Ok we can delete
+ $Res=$this->db->exec_sql("delete from jrn_rapt where ".
"(jra_concerned=$jr_id2 and
jr_id=".$this->jr_id.") or
(jra_concerned=".$this->jr_id." and
jr_id=$jr_id2) ");
}
@@ -153,8 +214,8 @@
/*!
*\brief Return an array of the concerned operation
- *
- *
+ *
+ *
*\param database connection
* \return array if something is found or null
*/
@@ -188,7 +249,7 @@
}
/**
address@hidden return array of not-reconciled operation
-
+
*/
function get_not_reconciled()
{
@@ -207,7 +268,7 @@
return $ret;
}
/**
- *Create a sql condition to filter by security and by asked ledger
+ *Create a sql condition to filter by security and by asked ledger
* based on $this->a_jrn
address@hidden a valid sql stmt to include
address@hidden get_not_reconciled get_reconciled
@@ -309,7 +370,7 @@
$user=new User($this->db);
list($start,$end)=$user->get_limit_current_exercice();
- if (isDate($this->start_day) ==null)
+ if (isDate($this->start_day) ==null)
{
$this->start_day=$start;
}
Modified: phpcompta/branches/rel560/include/class_lettering.php
===================================================================
--- phpcompta/branches/rel560/include/class_lettering.php 2011-12-16
01:56:02 UTC (rev 4614)
+++ phpcompta/branches/rel560/include/class_lettering.php 2011-12-16
01:56:39 UTC (rev 4615)
@@ -28,11 +28,11 @@
/**
address@hidden mother class for the lettering by account and by card
* use the tables jnt_letter, letter_deb and letter_cred
- * - "account"=>"account", => the accounting of the j_id (use by
Lettering_Account)
- * - "quick_code"=>"quick_code", => the quick_code of the j_id (used by
Lettering_Card)
- * - "start"=>"start", => date of the first day
- * - "end"=>"end", => date of the last day
- * - "sql_ledger"=>"sql_ledger" => the sql clause to filter on the available
ledgers
+ * - "account"=>"account", => the accounting of the j_id (use by
Lettering_Account)
+ * - "quick_code"=>"quick_code", => the quick_code of the j_id (used by
Lettering_Card)
+ * - "start"=>"start", => date of the first day
+ * - "end"=>"end", => date of the last day
+ * - "sql_ledger"=>"sql_ledger" => the sql clause to filter on the available
ledgers
*/
class Lettering
{
@@ -83,38 +83,102 @@
/**
*Use to just insert a couple of lettered operation
*/
- function insert_couple($j_id1,$j_id2)
- {
- $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq");
- $this->db->exec_sql('insert into jnt_letter(jl_id) values($1)',
- array($jl_id));
- /* take needed data */
- $first=$this->db->get_value('select j_debit from jrnx where
j_id=$1',array($j_id1));
- if ( $this->db->count() == 0 ) throw new Exception ('Opération non
existante');
+ function insert_couple($j_id1, $j_id2)
+ {
+ /* take needed data */
+ $first = $this->db->get_value('select j_debit from jrnx where
j_id=$1', array($j_id1));
+ if ($this->db->count() == 0)
+ throw new Exception('Opération non existante');
- $second=$this->db->get_value('select j_debit from jrnx where
j_id=$1',array($j_id2));
- if ( $this->db->count() == 0 ) throw new Exception ('Opération non
existante');
- /* insert */
- if ( $first == 't')
- {
- // save into letter_deb
- $ld_id=$this->db->get_value('insert into letter_deb(j_id,jl_id)
values($1,$2) returning ld_id',array($j_id1,$jl_id));
- }
- else
- {
- $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id)
values($1,$2) returning lc_id',array($j_id1,$jl_id));
- }
- if ( $second == 't')
- {
- // save into letter_deb
- $ld_id=$this->db->get_value('insert into letter_deb(j_id,jl_id)
values($1,$2) returning ld_id',array($j_id2,$jl_id));
- }
- else
- {
- $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id)
values($1,$2) returning lc_id',array($j_id2,$jl_id));
- }
+ $second = $this->db->get_value('select j_debit from jrnx where
j_id=$1', array($j_id2));
+ if ($this->db->count() == 0)
+ throw new Exception('Opération non existante');
+ $sql_already = "select distinct(jl_id)
+ from jnt_letter
+ left outer join letter_deb using (jl_id)
+ left outer join letter_cred using (jl_id)
+ where
+ letter_deb.j_id = $1 or letter_cred.j_id=$1";
+ $let1 = 0;
+ $let2 = 0;
+ $already = $this->db->get_array($sql_already, array($j_id1));
+ if (count($already) > 0)
+ {
+ if (count($already) == 1)
+ {
+ // retrieve the letter
+ $let1 = $this->db->get_value("select
distinct(jl_id)
+
from jnt_letter
+
left outer join letter_deb using (jl_id)
+
left outer join letter_cred using (jl_id)
+
where
+
letter_deb.j_id = $1 or letter_cred.j_id=$1", array($j_id1));
+ }
+ else
+ {
+ return;
+ }
+ }
- }
+ $already = $this->db->get_array($sql_already, array($j_id2));
+ if (count($already) > 0)
+ {
+ if (count($already) == 1)
+ {
+ // retrieve the letter
+ $let2 = $this->db->get_value("select
distinct(jl_id)
+
from jnt_letter
+
left outer join letter_deb using (jl_id)
+
left outer join letter_cred using (jl_id)
+
where
+
letter_deb.j_id = $1 or letter_cred.j_id=$1", array($j_id2));
+ }
+ else
+ {
+ return;
+ }
+ }
+ $jl_id = 0;
+ // already linked together
+ if ($let1 != 0 && $let1 == $let2)
+ return;
+
+ // already linked
+ if ($let1 != 0 && $let2 != 0 && $let1 != $let2)
+ return;
+
+ // none is linked
+ if ($let1 == 0 && $let2 == 0)
+ {
+ $jl_id =
$this->db->get_next_seq("jnt_letter_jl_id_seq");
+ $this->db->exec_sql('insert into jnt_letter(jl_id)
values($1)', array($jl_id));
+ }
+ // one is linked but not the other
+ if ($let1 == 0 && $let2 != 0)
+ $jl_id = $let2;
+ if ($let1 != 0 && $let2 == 0)
+ $jl_id = $let1;
+
+ /* insert */
+ if ($first == 't')
+ {
+ // save into letter_deb
+ $ld_id = $this->db->get_value('insert into
letter_deb(j_id,jl_id) values($1,$2) returning ld_id', array($j_id1, $jl_id));
+ }
+ else
+ {
+ $lc_id = $this->db->get_value('insert into
letter_cred(j_id,jl_id) values($1,$2) returning lc_id', array($j_id1, $jl_id));
+ }
+ if ($second == 't')
+ {
+ // save into letter_deb
+ $ld_id = $this->db->get_value('insert into
letter_deb(j_id,jl_id) values($1,$2) returning ld_id', array($j_id2, $jl_id));
+ }
+ else
+ {
+ $lc_id = $this->db->get_value('insert into
letter_cred(j_id,jl_id) values($1,$2) returning lc_id', array($j_id2, $jl_id));
+ }
+ }
public function get_info()
{
return var_export(self::$variable,true);
@@ -128,7 +192,7 @@
address@hidden $p_array
@code
'gDossier' => string '13' (length=2)
- 'letter_j_id' =>
+ 'letter_j_id' =>
array
0 => string '5' (length=1)
1 => string '23' (length=2)
@@ -229,7 +293,7 @@
return $r;
}
/**
- *show only the lettered records from jrnx
+ *show only the lettered records from jrnx
*it fills the array $this->content
*/
protected function show_lettered()
@@ -243,7 +307,7 @@
return $r;
}
/**
- *show only the not lettered records from jrnx
+ *show only the not lettered records from jrnx
*it fills the array $this->content
*/
protected function show_not_lettered()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpcompta-dev] r4615 - phpcompta/branches/rel560/include,
phpcompta-dev <=