[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpcompta-dev] r5645 - phpcompta/tags/rel671/include
From: |
phpcompta-dev |
Subject: |
[Phpcompta-dev] r5645 - phpcompta/tags/rel671/include |
Date: |
Tue, 7 Jan 2014 17:54:57 +0100 (CET) |
Author: danydb
Date: 2014-01-07 17:54:56 +0100 (Tue, 07 Jan 2014)
New Revision: 5645
Modified:
phpcompta/tags/rel671/include/class_acc_ledger_purchase.php
Log:
Rewrite and have one row by ND
Task #960 - TVA ND & comptabilit?\195?\169 analytique
Modified: phpcompta/tags/rel671/include/class_acc_ledger_purchase.php
===================================================================
--- phpcompta/tags/rel671/include/class_acc_ledger_purchase.php 2014-01-06
01:54:44 UTC (rev 5644)
+++ phpcompta/tags/rel671/include/class_acc_ledger_purchase.php 2014-01-07
16:54:56 UTC (rev 5645)
@@ -259,8 +259,146 @@
throw new Exception(_('Il n\'y a aucune marchandise'),12);
}
+ /**
+ *
+ * @param Acc_Compute $p_nd_amount
+ * @param Fiche $p_fiche
+ * @param type $p_tva_both
+ */
+ private function compute_no_deductible(Acc_Compute $p_nd_amount, Fiche
$p_fiche, $p_tva_both)
+ {
+ if (!$p_fiche->empty_attribute(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE))
+ {
+ $p_nd_amount->amount_nd_rate =
$p_fiche->strAttribut(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
+ $p_nd_amount->compute_nd();
+ }
+ if (!$p_fiche->empty_attribute(ATTR_DEF_DEP_PRIV))
+ {
+ $p_nd_amount->amount_perso_rate =
$p_fiche->strAttribut(ATTR_DEF_DEP_PRIV);
+ $p_nd_amount->compute_perso();
+ }
+
+ if (!$p_fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE) &&
$tva_both == 0)
+ {
+ $p_nd_amount->nd_vat_rate =
$p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE);
+ $p_nd_amount->compute_nd_vat();
+ }
+ if (!$p_fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP) &&
$p_tva_both == 0)
+ {
+ $p_nd_amount->nd_ded_vat_rate =
$p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
+ $p_nd_amount->compute_ndded_vat();
+ }
+ }
+ /**
+ *
+ * @param Acc_Compute $p_nd_amount
+ * @param Fiche $p_fiche
+ * @param type $p_tva_both
+ * @param type $p_tot_debit
+ */
+ private function insert_no_deductible(Acc_Compute $p_nd_amount, Fiche
$p_fiche, $p_tva_both,&$p_tot_debit,$p_acc_operation)
+ {
+ $p_nd_amount->correct();
+ /*
+ * Save all the no deductible
+ *
ATTR_DEF_ACCOUNT_ND_TVA,ATTR_DEF_ACCOUNT_ND_TVA_ND,ATTR_DEF_ACCOUNT_ND_PERSO,ATTR_DEF_ACCOUNT_ND
+ */
+ if ($p_nd_amount->amount_nd_rate != 0)
+ {
+ $dna_default = new Acc_Parm_Code($this->db, 'DNA');
+
+ /* save op. */
+ if (!$p_Fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND))
+ {
+ $dna = $p_Fiche->strAttribut(ATTR_DEF_ACCOUNT_ND);
+ } else
+ {
+ $dna = $dna_default->p_value;
+ }
+ $dna = ($dna == '') ? $dna_default->p_value : $dna;
+
+ $p_acc_operation->type = 'd';
+ $p_acc_operation->amount = $p_nd_amount->amount_nd_rate ;
+ $p_acc_operation->poste = $dna;
+ $p_acc_operation->qcode = '';
+
+ if ($p_nd_amount->amount_nd_rate > 0)
+ $p_tot_debit = bcadd($p_tot_debit,
$p_nd_amount->amount_nd_rate);
+ $j_id = $p_acc_operation->insert_jrnx();
+ }
+ /*
+ * ATTR_DEF_ACCOUNT_ND_PERSO
+ */
+ if ($p_nd_amount->amount_perso != 0)
+ {
+ $dna_default = new Acc_Parm_Code($this->db, 'DEP_PRIV');
+
+ /* save op. */
+ $p_acc_operation->type = 'd';
+ if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_PERSO))
+ {
+ $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_PERSO);
+ } else
+ {
+ $dna = $dna_default->p_value;
+ }
+ $dna = ($dna == '') ? $dna_default->p_value : $dna;
+
+ $p_acc_operation->amount = $p_nd_amount->amount_perso ;
+ $p_acc_operation->poste = $dna;
+ $p_acc_operation->qcode = '';
+ if ($p_nd_amount->amount_perso> 0)
+ $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_perso);
+ $j_id = $p_acc_operation->insert_jrnx();
+ }
+ if ($p_nd_amount->nd_vat != 0)
+ {
+ $dna_default = new Acc_Parm_Code($this->db, 'TVA_DNA');
+
+ /* save op. */
+ $p_acc_operation->type = 'd';
+ $p_acc_operation->qcode = '';
+ if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_TVA_ND) &&
$p_tva_both == 0)
+ {
+ $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA_ND);
+ } else
+ {
+ $dna = $dna_default->p_value;
+ }
+ $dna = ($dna == '') ? $dna_default->p_value : $dna;
+
+ $p_acc_operation->amount = $p_nd_amount->nd_vat;
+ $p_acc_operation->poste = $dna;
+
+ $j_id = $p_acc_operation->insert_jrnx();
+ }
+ if ($p_nd_amount->nd_ded_vat != 0)
+ {
+ $dna_default = new Acc_Parm_Code($this->db, 'TVA_DED_IMPOT');
+ /* save op. */
+ if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_TVA) &&
$p_tva_both == 0)
+ {
+ $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA);
+ } else
+ {
+ $dna = $dna_default->p_value;
+ }
+ $dna = ($dna == '') ? $dna_default->value : $dna;
+
+
+
+ $p_acc_operation->type = 'd';
+ $p_acc_operation->qcode = '';
+ $p_acc_operation->amount = $p_nd_amount->nd_ded_vat;
+ $p_acc_operation->poste = $dna;
+ 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();
+ }
+ }
+
/*!\brief insert into the database, it calls first the verify function
* change the value of this->jr_id and this->jr_internal.
* It generates the document and save the middle of payment, if
'gen_invoice is set
@@ -346,11 +484,9 @@
/* Save all the items without vat and no deductible vat and
expense*/
for ($i=0;$i< $nb_item;$i++)
{
- $n_both=0;
+ $n_both=0;
if ( strlen(trim(${'e_march'.$i})) == 0 ) continue;
- /* if ( ${'e_march'.$i.'_price'} == 0 ) continue;
- if ( ${'e_quant'.$i} == 0 ) continue;
-*/
+
/* First we save all the items without vat */
$fiche=new Fiche($this->db);
$fiche->get_by_qcode(${"e_march".$i});
@@ -364,12 +500,24 @@
$oTva->load();
$tva_both=$oTva->get_parameter("both_side");
}
-
+ /* -- Create acc_operation -- */
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='d';
+ $acc_operation->periode=$tperiode;
+ $acc_operation->qcode="";
+
+
/* We have to compute all the amount thanks Acc_Compute */
$amount=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
+
$acc_amount=new Acc_Compute();
$acc_amount->check=false;
$acc_amount->set_parameter('amount',$amount);
+
+
if ( $g_parameter->MY_TVA_USE=='Y')
{
$acc_amount->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
@@ -386,54 +534,17 @@
if ($tva_both==0)
$tot_tva=bcadd($tot_tva,$acc_amount->amount_vat);
}
- $acc_operation=new Acc_Operation($this->db);
- $acc_operation->date=$e_date;
- $acc_operation->grpt=$seq;
- $acc_operation->jrn=$p_jrn;
- $acc_operation->type='d';
- $acc_operation->periode=$tperiode;
- $acc_operation->qcode="";
- if ( $g_parameter->MY_UPDLAB=='Y')
- $acc_operation->desc=strip_tags(${"e_march".$i."_label"});
- else
- $acc_operation->desc=null;
+
+ /* 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);
- if ( !
$fiche->empty_attribute(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE))
- {
-
$acc_amount->amount_nd_rate=$fiche->strAttribut(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
- $acc_amount->compute_nd();
- $tot_nd+=$acc_amount->amount_nd;
-
- }
-
- if ( ! $fiche->empty_attribute(ATTR_DEF_DEP_PRIV))
- {
-
$acc_amount->amount_perso_rate=$fiche->strAttribut(ATTR_DEF_DEP_PRIV);
- $acc_amount->compute_perso();
- $tot_perso+=$acc_amount->amount_perso;
- }
-
- if ( ! $fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE) &&
$tva_both==0)
- {
-
$acc_amount->nd_vat_rate=$fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE);
- $acc_amount->compute_nd_vat();
- $tot_tva_nd+=$acc_amount->nd_vat;
- /* save op. */
-
- }
- if ( !
$fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP) && $tva_both==0)
- {
-
$acc_amount->nd_ded_vat_rate=$fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
- $acc_amount->compute_ndded_vat();
- /* save op. */
- $tot_tva_ndded+=$acc_amount->nd_ded_vat;
- }
- $acc_amount->correct();
- $tot_amount+=$amount;
-
/* get the account and explode if necessary */
$sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
// if 2 accounts, take only the debit one for customer
@@ -446,21 +557,24 @@
{
$poste_val=$sposte;
}
-
+ if ( $g_parameter->MY_UPDLAB=='Y')
+ $acc_operation->desc=strip_tags(${"e_march".$i."_label"});
+ else
+ $acc_operation->desc=null;
$acc_operation->poste=$poste_val;
$acc_operation->amount=$acc_amount->amount;
$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();
+
/* Compute sum vat */
-
if ( $g_parameter->MY_TVA_USE=='Y')
{
$tva_item=$acc_amount->amount_vat;
if (isset($tva[$idx_tva] ) )
- $tva[$idx_tva]+=$tva_item;
+ $tva[$idx_tva]=bcadd($tva[$idx_tva],$tva_item);
else
$tva[$idx_tva]=$tva_item;
@@ -508,7 +622,7 @@
",".$acc_amount->amount_nd. /*
8 */
",".$acc_amount->nd_vat. /*
9 */
",".$acc_amount->nd_ded_vat. /*
10 */
- ",".$acc_amount->amount_perso. /*
11 */
+ ",".$acc_amount->amount_perso. /*
11 */
",'".$e_client."',".$n_both.")");
/* 12 */
}
@@ -546,108 +660,8 @@
if ( $cust_amount < 0 )
$tot_debit=bcadd($tot_debit,abs($cust_amount));
$let_client=$acc_operation->insert_jrnx();
- /*
- * Save all the no deductible
- *
ATTR_DEF_ACCOUNT_ND_TVA,ATTR_DEF_ACCOUNT_ND_TVA_ND,ATTR_DEF_ACCOUNT_ND_PERSO,ATTR_DEF_ACCOUNT_ND
- */
- if ( $tot_nd != 0)
- {
- $dna_default=new Acc_Parm_Code($this->db,'DNA');
+
- /* save op. */
- if ( ! $fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND))
- {
- $dna=$fiche->strAttribut(ATTR_DEF_ACCOUNT_ND);
- }
- else
- {
- $dna=$dna_default->p_value;
- }
- $dna=($dna=='')?$dna_default->p_value:$dna;
-
- $acc_operation->type='d';
- $acc_operation->amount=$tot_nd;
- $acc_operation->poste=$dna;
- $acc_operation->qcode='';
- if ( $tot_nd > 0 ) $tot_debit=bcadd($tot_debit,$tot_nd);
- $j_id=$acc_operation->insert_jrnx();
-
- }
- /*
- *ATTR_DEF_ACCOUNT_ND_PERSO
- */
- if ( $tot_perso != 0)
- {
- $dna_default=new Acc_Parm_Code($this->db,'DEP_PRIV');
-
- /* save op. */
- $acc_operation->type='d';
- if ( ! $fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_PERSO))
- {
- $dna=$fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_PERSO);
- }
- else
- {
- $dna=$dna_default->p_value;
- }
- $dna=($dna=='')?$dna_default->p_value:$dna;
-
- $acc_operation->amount=$tot_perso;
- $acc_operation->poste=$dna;
- $acc_operation->qcode='';
- if ( $tot_perso > 0 ) $tot_debit=bcadd($tot_debit,$tot_perso);
- $j_id=$acc_operation->insert_jrnx();
-
- }
- if ( $tot_tva_nd != 0)
- {
- $dna_default=new Acc_Parm_Code($this->db,'TVA_DNA');
-
- /* save op. */
- $acc_operation->type='d';
- $acc_operation->qcode='';
- if ( ! $fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_TVA_ND) &&
$tva_both==0)
- {
- $dna=$fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA_ND);
- }
- else
- {
- $dna=$dna_default->p_value;
- }
- $dna=($dna=='')?$dna_default->p_value:$dna;
-
- $acc_operation->amount=$tot_tva_nd;
- $acc_operation->poste=$dna;
- if ( $tot_tva_nd > 0 )
$tot_debit=bcadd($tot_debit,$tot_tva_nd);
- $j_id=$acc_operation->insert_jrnx();
-
- }
- if ( $tot_tva_ndded != 0)
- {
- $dna_default=new Acc_Parm_Code($this->db,'TVA_DED_IMPOT');
- /* save op. */
- if ( ! $fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_TVA) &&
$tva_both==0)
- {
- $dna=$fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA);
- }
- else
- {
- $dna=$dna_default->p_value;
- }
- $dna=($dna=='')?$dna_default->value:$dna;
-
-
-
- $acc_operation->type='d';
- $acc_operation->qcode='';
- $acc_operation->amount=$tot_tva_ndded;
- $acc_operation->poste=$dna;
- if ( $tot_tva_ndded > 0 )
$tot_debit=bcadd($tot_debit,$tot_tva_ndded);
- $j_id=$acc_operation->insert_jrnx();
-
-
- }
-
if ( $g_parameter->MY_TVA_USE=='Y')
{
/* save all vat
---
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] r5645 - phpcompta/tags/rel671/include,
phpcompta-dev <=