phpcompta-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpcompta-dev] r5650 - in phpcompta/tags/rel671: html/admin/sql/patch i


From: phpcompta-dev
Subject: [Phpcompta-dev] r5650 - in phpcompta/tags/rel671: html/admin/sql/patch include
Date: Wed, 8 Jan 2014 21:48:45 +0100 (CET)

Author: danydb
Date: 2014-01-08 21:48:44 +0100 (Wed, 08 Jan 2014)
New Revision: 5650

Added:
   phpcompta/tags/rel671/html/admin/sql/patch/upgrade112.sql
Modified:
   phpcompta/tags/rel671/include/class_acc_ledger_purchase.php
   phpcompta/tags/rel671/include/class_anc_operation.php
   phpcompta/tags/rel671/include/constant.php
Log:
Task #960 - TVA ND & comptabilit?\195?\169 analytique
TVA ND is now in the Analytic accountancy
The Analytic Accountancy can work with negative amount

Added: phpcompta/tags/rel671/html/admin/sql/patch/upgrade112.sql
===================================================================
--- phpcompta/tags/rel671/html/admin/sql/patch/upgrade112.sql                   
        (rev 0)
+++ phpcompta/tags/rel671/html/admin/sql/patch/upgrade112.sql   2014-01-08 
20:48:44 UTC (rev 5650)
@@ -0,0 +1,11 @@
+begin;
+
+ALTER TABLE operation_analytique ADD COLUMN oa_jrnx_id_source bigint;
+COMMENT ON COLUMN operation_analytique.oa_jrnx_id_source IS 'jrnx.j_id source 
of this amount, this amount is computed from an amount giving a ND VAT.Normally 
NULL  is there is no ND VAT.';
+
+ALTER TABLE operation_analytique ALTER COLUMN oa_signed SET DEFAULT 
'Y'::bpchar;
+COMMENT ON COLUMN operation_analytique.oa_signed IS 'Sign of the amount';
+
+update version set val=113;
+
+commit;
\ No newline at end of file

Modified: phpcompta/tags/rel671/include/class_acc_ledger_purchase.php
===================================================================
--- phpcompta/tags/rel671/include/class_acc_ledger_purchase.php 2014-01-07 
20:22:48 UTC (rev 5649)
+++ phpcompta/tags/rel671/include/class_acc_ledger_purchase.php 2014-01-08 
20:48:44 UTC (rev 5650)
@@ -295,14 +295,24 @@
     }
 
     /**
-     * Insert into JRNX the No Deductible amount
+     * Insert into JRNX the No Deductible amount and into Analytic Accountancy 
for the ND VAT
      * @param Acc_Compute $p_nd_amount content ND amount
      * @param Fiche $p_fiche Card of the Service
      * @param type $p_tva_both  0 if TVA is normal or 1 if on both side
      * @param type $p_tot_debit total debit
+     * @param $p_acc_operation Acc_Operation for inserting into jrnx
+     * @param $p_group group for AC
+     * @param $idx row number
+     * 
+     * @see Acc_Ledger_Purchase::insert
      */
-    private function insert_no_deductible(Acc_Compute $p_nd_amount, Fiche 
$p_fiche, $p_tva_both,&$p_tot_debit,$p_acc_operation)
+    private function insert_no_deductible(Acc_Compute $p_nd_amount, Fiche 
$p_fiche, $p_tva_both,&$p_tot_debit,Acc_Operation 
$p_acc_operation,$p_group,$idx)
     {
+        global $g_parameter;
+        if ($p_acc_operation->jrnx_id == 0) {
+            throw new Exception(__FILE__.__LINE__.'invalid 
acc_operation.j_id');
+        }
+        $source_j_id=$p_acc_operation->jrnx_id ;
         $p_nd_amount->correct();
         /*
          * Save all the no deductible
@@ -377,6 +387,18 @@
             $p_acc_operation->poste = $dna;
             $p_acc_operation->desc=$this->find_label($dna)." ND_TVA 
".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
             $j_id = $p_acc_operation->insert_jrnx();
+            if ( $g_parameter->MY_ANALYTIC != "nu" )
+            {
+                $op=new Anc_Operation($this->db);
+                $op->oa_group=$p_group;
+                $op->j_id=$j_id;
+                $op->oa_date=$p_acc_operation->date;
+
+                $op->oa_debit=($p_nd_amount->nd_vat > 0 )?'t':'f';
+                $op->oa_description=sql_string('ND_TVA');
+                $op->oa_jrnx_id_source=$source_j_id;
+                
$op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_vat,$p_acc_operation->jrnx_id);
+            }
         }
         if ($p_nd_amount->nd_ded_vat != 0)
         {
@@ -401,6 +423,18 @@
             if ($p_nd_amount->nd_ded_vat > 0)
                 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_ded_vat);
             $j_id = $p_acc_operation->insert_jrnx();
+           if ( $g_parameter->MY_ANALYTIC != "nu" )
+            {
+                $op=new Anc_Operation($this->db);
+                $op->oa_group=$p_group;
+                $op->j_id=$j_id;
+                $op->oa_date=$p_acc_operation->date;
+
+                $op->oa_debit=($p_nd_amount->nd_ded_vat > 0 )?'t':'f';
+                $op->oa_description=sql_string('DED_TVA ');
+                $op->oa_jrnx_id_source=$source_j_id;
+                
$op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_ded_vat);
+            }
         }
     }
 
@@ -543,10 +577,8 @@
                 /* compute ND */
                 $this->compute_no_deductible($acc_amount, $fiche, $tva_both);
 
-                /* insert ND */
-                $this->insert_no_deductible($acc_amount, $fiche, $tva_both, 
$tot_debit,$acc_operation);
+                
 
-
               
                 $tot_amount=bcadd($tot_amount,$amount);
 
@@ -571,6 +603,9 @@
                 $acc_operation->qcode=${"e_march".$i};
                 if( $acc_amount->amount > 0 ) 
$tot_debit=bcadd($tot_debit,$acc_amount->amount);
                 $j_id=$acc_operation->insert_jrnx();
+                
+                /* insert ND */
+                $this->insert_no_deductible($acc_amount, $fiche, $tva_both, 
$tot_debit,$acc_operation,$group,$i);
 
                 
                 /* Compute sum vat */
@@ -605,8 +640,7 @@
                     $op->oa_group=$group;
                     $op->j_id=$j_id;
                     $op->oa_date=$e_date;
-
-                    $op->oa_debit=($amount > 0 )?'t':'f';
+                    $op->oa_debit='t';
                     $op->oa_description=sql_string($e_comm);
                     $op->save_form_plan($_POST,$i,$j_id);
                 }

Modified: phpcompta/tags/rel671/include/class_anc_operation.php
===================================================================
--- phpcompta/tags/rel671/include/class_anc_operation.php       2014-01-07 
20:22:48 UTC (rev 5649)
+++ phpcompta/tags/rel671/include/class_anc_operation.php       2014-01-08 
20:48:44 UTC (rev 5650)
@@ -50,7 +50,17 @@
     var $oa_group;   /*!< group of operation  */
     var $oa_date;         /*!< equal to j_date if j_id is not    null */
     var $pa_id;        /*!< the plan analytique id */
-
+    /**
+     * In the case, the amount comes from a ND VAT, the variable
+     * contents the jrnx.j_id of the source which was used to compute 
+     * the amount
+     */
+    var $oa_jrnx_id_source; 
+    /**
+     * @brief signed of the amount
+     */
+    var $oa_signed;
+    
     /*!\brief constructor
      *
      */
@@ -58,6 +68,8 @@
     {
         $this->db=$p_cn;
         $this->id=$p_id;
+        $this->oa_jrnx_id_source=null;
+        $this->oa_signed='Y';
     }
     /*!\brief add a row  to the table operation_analytique
      * \note if $this->oa_group if 0 then a sequence id will be computed for
@@ -74,36 +86,47 @@
 
         if ( $this->j_id == 0 )
         {
-            $this->j_id="null";
+            $this->j_id=null;
         }
 
 
         // we don't save null operations
         if ( $this->oa_amount == 0 || $this->po_id==-1)
             return;
-
-        $oa_row=(isset($this->oa_row))?$this->oa_row:"NULL";
-        $sql='insert into operation_analytique (
-             po_id,
+        
+        if ( $this->oa_amount< 0) 
+        {
+            $this->oa_debit=($this->oa_debit=='t')?'f':'t';
+            $this->oa_signed='N';
+        }
+        
+        $oa_row=(isset($this->oa_row))?$this->oa_row:null;
+        $sql="insert into operation_analytique (
+             po_id, 
              oa_amount,
              oa_description,
              oa_debit,
              oa_group,
              j_id,
              oa_date,
-             oa_row
-             ) values ('.
-             $this->po_id.",".
-             $this->oa_amount.",".
-             "' ".Database::escape_string($this->oa_description)."',".
-             "'".$this->oa_debit."',".
-             $this->oa_group.",".
-             $this->j_id.",".
-             "to_date('".$this->oa_date."','DD.MM.YYYY'),".$oa_row.")";
+             oa_row,
+             oa_jrnx_id_source,
+             oa_signed
+             ) values ($1,$2,$3,$4,$5,$6,to_date($7,'DD.MM.YYYY'),$8,$9,$10)";
 
+        $this->db->exec_sql($sql,array(
+                $this->po_id, // 1
+                abs($this->oa_amount), //2
+                $this->oa_description, //3
+                $this->oa_debit, //4
+                $this->oa_group, //5
+                $this->j_id, //6
+                $this->oa_date, //7
+                $oa_row, //8
+                $this->oa_jrnx_id_source, //8
+                $this->oa_signed
+                ));
 
-        $this->db->exec_sql($sql);
-
     }
     /*!\brief delete a row from the table operation_analytique
      * \note be carefull : do not delete a row when we have a group
@@ -289,7 +312,7 @@
     }
     /*!\brief retrieve an operation thanks a jrnx.j_id
      * \param the jrnx.j_id
-     * \return false if nothing is found other true
+     * \return null if nothing is found other an array
      */
     function get_by_jid($p_jid)
     {
@@ -302,7 +325,8 @@
              oa_group,
              oa_date,
              pa_id,
-             oa_row
+             oa_row,
+             oa_signed
              from operation_analytique join poste_analytique using (po_id)
              where
              j_id=$p_jid order by j_id,oa_row,pa_id";
@@ -502,7 +526,7 @@
                        
$value->javascript='onchange="format_number(this);anc_refresh_remain(\''.$table_id.'\',\''.$p_seq.'\')"';
             $value->name="val[".$p_seq."][]";
             $value->size=6;
-            
$value->value=abs((isset($val[$p_seq][$i]))?$val[$p_seq][$i]:$p_amount);
+            $value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:$p_amount;
             $value->readOnly=($p_mode==1)?false:true;
                        $remain=bcsub($remain,$value->value);
             $result.='<td>'.$value->input().'</td>';
@@ -511,21 +535,100 @@
         }
 
         $result.="</table>";
-               $style_remain=($remain==0)?'style="color:green"':' 
style="color:red"';
-               $result.=" Reste à imputer =  ".
-                               '<span class="remain" '.$style_remain.' 
id="'.$ctrl_remain.'">'.
-                               $remain.'</span>';
+        if ( $p_mode == 1 )
+        {
+            $style_remain=($remain==0)?'style="color:green"':' 
style="color:red"';
+            $result.=" Reste à imputer =  ".
+                            '<span class="remain" '.$style_remain.' 
id="'.$ctrl_remain.'">'.
+                            $remain.'</span>';
 
-        // add a button to add a row
-        $button=new IButton();
-        $button->javascript="add_row('".$p_id."$table_id',$p_seq);";
-        $button->name="js".$p_id.$p_seq;
-        $button->label="Nouvelle ligne";
-        if ( $p_mode == 1 )
+            // add a button to add a row
+            $button=new IButton();
+            $button->javascript="add_row('".$p_id."$table_id',$p_seq);";
+            $button->name="js".$p_id.$p_seq;
+            $button->label="Nouvelle ligne";
+
             $result.="<br>".$button->input();
+        }
 
         return $result;
     }
+    /**
+     * Save the ND VAT with prorata
+     * 
+     * @param $p_array usually $_POST
+     * @param $p_item item of the form
+     * @param $p_j_id jrnx.j_id concerned writing
+     * @param $p_nd amount nd vat
+     * @see Anc_Operation::save_form_plan_vat_nd
+     * @return type
+     */
+    function save_form_plan_vat_nd($p_array,$p_item,$p_j_id,$p_nd)
+    {
+        bcscale(4);
+        extract($p_array);
+       if (! isset ($hplan) ) return;
+        
+        if ( ! isset(${'amount_t'.$p_item}) )
+            throw new Exception ('amount not set');
+        
+        $tot=0;
+        /* variable for in array
+           pa_id array of existing pa_id
+           hplan double array with the pa_id (column)
+           val double array by row with amount
+           op contains sequence
+           p_item is used to identify what op is concerned
+        */
+        /* echo "j_id = $j_id p_item = $p_item 
hplan=".var_export($hplan[$p_item],true)." val = 
".var_export($val[$p_item],true).'<br>'; */
+        /* for each row */
+        //   for ($i=0;$i<count($val[$p_item]);$i++) {
+        $idx_pa_id=0;
+        $row=0;
+        $a_Anc_Operation=array();
+        // foreach col PA
+        for ($e=0;$e<count($hplan[$p_item]);$e++)
+        {
+            if ( $idx_pa_id == count($pa_id))
+            {
+                $idx_pa_id=0;
+                $row++;
+            }
+            if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
+            {
+                $op=new Anc_Operation($this->db);
+                $op->po_id=$hplan[$p_item][$e];
+                $op->oa_group=$this->oa_group;
+                $op->j_id=$p_j_id;
+                $ratio=bcdiv($val[$p_item][$row],${"amount_t".$p_item});
+                $amount=  bcmul($p_nd, $ratio);
+                $op->oa_amount=abs(round($amount,2));
+                $op->oa_debit=$this->oa_debit;
+                $op->oa_date=$this->oa_date;
+
+                $op->oa_description=$this->oa_description;
+                $op->oa_row=$row;
+                $op->oa_jrnx_id_source=$this->oa_jrnx_id_source;
+                $a_Anc_Operation[]=clone $op;
+            }
+            $idx_pa_id++;
+        }
+        $nb_op=count($a_Anc_Operation);
+        bcscale(2);
+        for ($i=0;$i<$nb_op;$i++)
+        {
+            $tot=bcadd($tot,$a_Anc_Operation[$i]->oa_amount);
+        }
+        if ( $tot != $p_nd )
+        {
+            $diff=  bcsub($tot, $p_nd);
+            
$a_Anc_Operation[0]->oa_amount=bcsub($a_Anc_Operation[0]->oa_amount,$diff);
+        }
+        for ($i=0;$i<$nb_op;$i++)
+        {
+            $a_Anc_Operation[$i]->add();
+        }
+    }
     /*!\brief it called for each item, the data are taken from $p_array
      *  data and set before in this.
      * \param $p_item if the item nb for each item (purchase or selling
@@ -577,7 +680,7 @@
                 $op->po_id=$hplan[$p_item][$e];
                 $op->oa_group=$this->oa_group;
                 $op->j_id=$p_j_id;
-                $op->oa_amount=abs($val[$p_item][$row]);
+                $op->oa_amount=$val[$p_item][$row];
                 $op->oa_debit=$this->oa_debit;
                 $op->oa_date=$this->oa_date;
 
@@ -602,24 +705,49 @@
     */
     function save_update_form($p_array)
     {
-        extract ($p_array);
-        for ($i=0;$i < count($op);$i++)
+        extract($p_array);
+        for ($i = 0; $i < count($op); $i++)
         {
             /* clean jrnx */
-            $this->db->exec_sql('delete from operation_analytique where 
j_id=$1',array($op[$i]));
+            $this->db->exec_sql('delete from operation_analytique where 
j_id=$1', array($op[$i]));
+
             /* get missing data for adding */
-            $a_missing=$this->db->get_array("select 
to_char(jr_date,'DD.MM.YYYY') as mdate,j_montant,j_debit,jr_comment from jrnx 
join jrn on (j_grpt=jr_grpt_id) where j_id=$1",
-                                            array($op[$i]));
-            $missing=$a_missing[0];
-            $this->oa_debit=$missing['j_debit'];
-            $this->oa_description=$missing['jr_comment'];
-            $this->j_id=$op[$i];
-            $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
-            $this->oa_group=$group;
-            $this->oa_date=$missing['mdate'];
-            $this->save_form_plan($p_array,$i,$op[$i]);
+            $a_missing = $this->db->get_array("select 
to_char(jr_date,'DD.MM.YYYY') as mdate,j_montant,j_debit,jr_comment from jrnx 
join jrn on (j_grpt=jr_grpt_id) where j_id=$1", array($op[$i]));
+            $missing = $a_missing[0];
+            $this->oa_debit = $missing['j_debit'];
+            $this->oa_description = $missing['jr_comment'];
+            $this->j_id = $op[$i];
+            $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
+            $this->oa_group = $group;
+            $this->oa_date = $missing['mdate'];
+            $this->save_form_plan($p_array, $i, $op[$i]);
+            
+            // There is ND VAT amount
+            $a_nd = $this->db->get_array('select j_id from operation_analytique
+                where oa_jrnx_id_source=$1', array($op[$i]));
+            if (count($a_nd) > 0)
+            {
+                // for each ND VAT amount
+                for ($e=0;$e<count($a_nd);$e++)
+                {
+                    $this->db->exec_sql('delete from operation_analytique 
where j_id=$1', array($a_nd[$e]['j_id']));
+                    /* get missing data for adding */
+                    $a_missing_vat = $this->db->get_array("select 
to_char(jr_date,'DD.MM.YYYY') as mdate,j_montant,j_debit,jr_comment from jrnx 
join jrn on (j_grpt=jr_grpt_id) where j_id=$1", array($a_nd[$e]['j_id']));
+                    $missing_vat = $a_missing_vat[0];
+                    $this->oa_debit = $missing_vat['j_debit'];
+                    $this->oa_description = $missing_vat['jr_comment'];
+                    $this->j_id = $op[$i];
+                    $group = $this->db->get_next_seq("s_oa_group"); /* for 
analytic */
+                    $this->oa_group = $group;
+                    $this->oa_date = $missing_vat['mdate'];
+                    $this->oa_jrnx_id_source=$op[$i];
+                    $p_array['amount_t'.$i]=$missing['j_montant'];
+                    $this->save_form_plan_vat_nd($p_array, $i, 
$a_nd[$e]['j_id'],$missing_vat['j_montant']);
+                }
+            }
         }
     }
+
     /*\brief transform a array of operation into a array usage by
      *display_form_plan & save_form_plan
      *\param $p_array array of operation
@@ -651,7 +779,7 @@
         $idx_pa=0;
         for ($i=0;$i < count($p_array);$i++)
         {
-            $val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
+            
$val[$p_line][$p_array[$i]->oa_row]=($p_array[$i]->oa_signed=='Y')?$p_array[$i]->oa_amount:($p_array[$i]->oa_amount*(-1));
         }
         $result['val']=$val;
         return $result;

Modified: phpcompta/tags/rel671/include/constant.php
===================================================================
--- phpcompta/tags/rel671/include/constant.php  2014-01-07 20:22:48 UTC (rev 
5649)
+++ phpcompta/tags/rel671/include/constant.php  2014-01-08 20:48:44 UTC (rev 
5650)
@@ -71,7 +71,7 @@
 define 
("SITE_UPDATE_PLUGIN",'http://www.phpcompta.eu/plugin_last_version.txt');
 
 
-define ("DBVERSION",112);
+define ("DBVERSION",113);
 define ("MONO_DATABASE",25);
 define ("DBVERSIONREPO",14);
 define ('NOTFOUND','--not found--');



---
PhpCompta est un logiciel de comptabilité libre en ligne (full web)
Projet opensource http://www.phpcompta.eu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]