diff --git a/html/admin/sql/patch/upgrade112.sql b/html/admin/sql/patch/upgrade112.sql new file mode 100644 index 000000000..786ee728f --- /dev/null +++ b/html/admin/sql/patch/upgrade112.sql @@ -0,0 +1,15 @@ +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 ADD COLUMN oa_signed character(1); +ALTER TABLE operation_analytique ALTER COLUMN oa_signed SET DEFAULT 'Y'::bpchar; +update operation_analytique set oa_signed='Y'; +ALTER TABLE operation_analytique ALTER COLUMN oa_signed SET NOT NULL; + +COMMENT ON COLUMN operation_analytique.oa_signed IS 'Sign of the amount'; + +update version set val=113; + +commit; \ No newline at end of file diff --git a/html/style-color.css b/html/style-color.css index 41f0e10dc..9b60946a2 100644 --- a/html/style-color.css +++ b/html/style-color.css @@ -201,7 +201,7 @@ div.searchmenu { div.recherche_form{ width:700px; - font-size:0.75em;; + font-size:0.75em; font-family:arial,verdana,sans-serif,helvetica; border-style:outset; border-width:1px; @@ -212,7 +212,6 @@ div.redcontent{ float:left; padding-top:7px; padding-left:8px; - font-size:0.75em;; font-family:arial,verdana,sans-serif,helvetica; width:75%; @@ -1051,9 +1050,7 @@ div#wait_box text-align:center; } div#div_jrnsearch_op{ - border:1px solid black; - display:none; width:50em; background-color:#EDF3FF; position:absolute; diff --git a/html/style-epad.css b/html/style-epad.css index 57ed3342b..17ba4f2d0 100644 --- a/html/style-epad.css +++ b/html/style-epad.css @@ -201,7 +201,6 @@ div.redcontent{ float:left; padding-top:7px; padding-left:8px; - font-size:0.75em;; font-family:arial,verdana,sans-serif,helvetica; width:75%; @@ -955,10 +954,8 @@ div.op_detail_title { } div#div_jrn{ - position:absolute; border:1px solid black; top:15%;left:100; - visibility:hidden; z-index:2; width:50em; background-color:#EDF3FF; diff --git a/html/style-light.css b/html/style-light.css index 3a6ec7ff5..e1ac0fcd7 100644 --- a/html/style-light.css +++ b/html/style-light.css @@ -197,11 +197,9 @@ div.recherche_form{ } div.redcontent{ - float:left; padding-top:7px; padding-left:8px; - font-size:0.75em;; font-family:arial,verdana,sans-serif,helvetica; width:75%; diff --git a/html/style.css b/html/style.css index e0371c7fb..e13c3a539 100644 --- a/html/style.css +++ b/html/style.css @@ -201,7 +201,6 @@ div.redcontent{ float:left; padding-top:7px; padding-left:8px; - font-size:0.75em;; font-family:arial,verdana,sans-serif,helvetica; width:75%; diff --git a/html/test.php b/html/test.php index 16fe7e6b3..4bdd8773e 100644 --- a/html/test.php +++ b/html/test.php @@ -40,6 +40,12 @@ if ( ! file_exists('authorized_debug') ) } html_page_start(); +function start_test($p_array) +{ + echo '

'.$p_array['desc'].'

'; + require $p_array['file']; + call_user_func($p_array['function']); +} // Test the connection echo __FILE__.":".__LINE__; print_r($_REQUEST); @@ -52,10 +58,17 @@ if ( ! isset($_REQUEST['gDossier'])) $cn=new Database($_GET['gDossier']); $a_route[]=array('desc'=>'test sur les menus par défauts','file'=>'class_default_menu.php','function'=>'Default_Menu::test_me'); - -for ($i=0;$i< count($a_route);$i++) +$a_route[]=array('desc'=>'test sur Acc_Operations','file'=>'class_acc_operation.php','function'=>'Acc_Operation::test_me'); +$a_route[]=array('desc'=>'test sur INVOICING','file'=>'../include/ext/invoicing/include/class_acc_ledger_sold_generate.php','function'=>'Acc_Ledger_Sold_Generate::test_me'); +$called=HtmlInput::default_value_get("called", -1); +if ($called == -1 ) { - echo '

'.$a_route[$i]['desc'].'

'; - require $a_route[$i]['file']; - call_user_func($a_route[$i]['function']); + for ($i=0;$i< count($a_route);$i++) + { + start_test($a_route[$i]); + } +} + else +{ + start_test($a_route[$called]); } \ No newline at end of file diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index 19b83953c..6ad07501d 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -3717,6 +3717,16 @@ class Acc_Ledger extends jrn_def_sql return $array; } + /** + * Retrieve the label of an accounting + * @param $p_value tmp_pcmn.pcm_val + * @return string + */ + protected function find_label($p_value) + { + $lib=$this->db->get_value('select pcm_lib from tmp_pcmn where pcm_val=$1',array($p_value)); + return $lib; + } } ?> \ No newline at end of file diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php index 38c9ed9cc..aa60638e1 100644 --- a/include/class_acc_ledger_purchase.php +++ b/include/class_acc_ledger_purchase.php @@ -259,7 +259,184 @@ class Acc_Ledger_Purchase extends Acc_Ledger throw new Exception(_('Il n\'y a aucune marchandise'),12); } + /** + * Compute the ND amount thanks the attribute of the concerned card. The object + * $p_nd_amount will changed + * + * @param Acc_Compute $p_nd_amount object with ND amount + * @param Fiche $p_fiche Concerned Card (purchase items) + * @param type $p_tva_bot 0 TVA on one side, 1 TVA on both side + */ + 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(); + } + } + + /** + * 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,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 + * 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 = ''; + $p_acc_operation->desc=$this->find_label($dna)." ND ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE); + 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 = ''; + $p_acc_operation->desc=$this->find_label($dna)." ND_PRIV ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE); + 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; + $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) + { + $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; + $p_acc_operation->desc=$this->find_label($dna)." DED_TVA ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE); + 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); + } + } + } /*!\brief insert into the database, it calls first the verify function * change the value of this->jr_id and this->jr_internal. @@ -346,11 +523,9 @@ class Acc_Ledger_Purchase extends Acc_Ledger /* 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 +539,24 @@ class Acc_Ledger_Purchase extends Acc_Ledger $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,53 +573,14 @@ class Acc_Ledger_Purchase extends Acc_Ledger 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); + - - - 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; + + $tot_amount=bcadd($tot_amount,$amount); /* get the account and explode if necessary */ $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT); @@ -446,21 +594,27 @@ class Acc_Ledger_Purchase extends Acc_Ledger { $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(); + + /* insert ND */ + $this->insert_no_deductible($acc_amount, $fiche, $tva_both, $tot_debit,$acc_operation,$group,$i); + /* 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; @@ -486,8 +640,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $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); } @@ -508,7 +661,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger ",".$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,107 +699,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger 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') { diff --git a/include/class_acc_operation.php b/include/class_acc_operation.php index 60361dcae..cd9f15a56 100644 --- a/include/class_acc_operation.php +++ b/include/class_acc_operation.php @@ -566,12 +566,13 @@ class Acc_Operation { $_SESSION['g_user']='phpcompta'; $_SESSION['g_pass']='dany'; - + global $g_user; $cn=new Database(dossier::id()); + $g_user=new User($cn); $a=new Acc_Operation($cn); - $a->jr_id=11; + $a->jr_id=1444; $b=$a->get_quant(); - var_dump($b->det); + var_dump($b); } } ///////////////////////////////////////////////////////////////////////////// @@ -653,6 +654,7 @@ class Acc_Sold extends Acc_Detail FROM quant_sold join jrnx using(j_id) where j_grpt=$1"; $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id)); } + } ///////////////////////////////////////////////////////////////////////////// /** diff --git a/include/class_anc_balance_double.php b/include/class_anc_balance_double.php index 7c8d530fd..6489102ce 100644 --- a/include/class_anc_balance_double.php +++ b/include/class_anc_balance_double.php @@ -65,7 +65,7 @@ class Anc_Balance_Double extends Anc_Print { $odd++; - $r.=($odd%2==0)?'':''; + $r.=($odd%2==0)?'':''; if ( $old == $row['a_po_name'] ) { diff --git a/include/class_anc_balance_simple.php b/include/class_anc_balance_simple.php index e8b9e8db9..8aae4a0ee 100644 --- a/include/class_anc_balance_simple.php +++ b/include/class_anc_balance_simple.php @@ -141,7 +141,7 @@ class Anc_Balance_Simple extends Anc_Print { $odd++; - $r.=($odd%2==0)?'':''; + $r.=($odd%2==0)?'':''; // the name and po_id // $r.=sprintf("%s",$row['po_id']); $r.=sprintf("%s",h($row['po_name'])); diff --git a/include/class_anc_grandlivre.php b/include/class_anc_grandlivre.php index 95f073dcf..0bbefa760 100644 --- a/include/class_anc_grandlivre.php +++ b/include/class_anc_grandlivre.php @@ -138,8 +138,9 @@ class Anc_GrandLivre extends Anc_Print return $r; } $r.= ''; - $ix=0;$prev='xx'; + $ix=0;$prev='xx';$idx=0; $tot_deb=$tot_cred=0; + foreach ( $array as $row ) { if ($prev != $row['po_name']) @@ -166,8 +167,8 @@ class Anc_GrandLivre extends Anc_Print $prev=$row['po_name']; $ix++; } - - $r.= ''; + $class=($idx%2==0)?'even':'odd'; $idx++; + $r.=''; $detail=($row['jr_id'] != null)?HtmlInput::detail_op($row['jr_id'],$row['jr_internal']):''; $post_detail=($row['j_poste'] != null)?HtmlInput::history_account($row['j_poste'],$row['j_poste']):''; $card_detail=($row['f_id'] != null)?HtmlInput::history_card($row['f_id'],$row['qcode']):''; diff --git a/include/class_anc_listing.php b/include/class_anc_listing.php index 8d3fc3a3a..5de43e2c0 100644 --- a/include/class_anc_listing.php +++ b/include/class_anc_listing.php @@ -63,6 +63,7 @@ class Anc_Listing extends Anc_Print function display_html() { + $idx=0; $r=""; //---Html $array=$this->load(); @@ -91,7 +92,9 @@ class Anc_Listing extends Anc_Print ''; foreach ( $array as $row ) { - $r.= ''; + $class=($idx%2==0)?'even':'odd'; + $idx++; + $r.= ''; $detail=($row['jr_id'] != null)?HtmlInput::detail_op($row['jr_id'],$row['jr_internal']):''; $post_detail=($row['j_poste'] != null)?HtmlInput::history_account($row['j_poste'],$row['j_poste']):''; $card_detail=($row['f_id'] != null)?HtmlInput::history_card($row['f_id'],$row['qcode']):''; diff --git a/include/class_anc_operation.php b/include/class_anc_operation.php index 580fa60c9..d838a853a 100644 --- a/include/class_anc_operation.php +++ b/include/class_anc_operation.php @@ -50,7 +50,17 @@ class Anc_Operation 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_positive; + /*!\brief constructor * */ @@ -58,6 +68,8 @@ class Anc_Operation { $this->db=$p_cn; $this->id=$p_id; + $this->oa_jrnx_id_source=null; + $this->oa_positive='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,35 +86,46 @@ class Anc_Operation 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_positive='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_positive + ) values ($1,$2,$3,$4,$5,$6,to_date($7,'DD.MM.YYYY'),$8,$9,$10)"; - - $this->db->exec_sql($sql); + $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_positive + )); } /*!\brief delete a row from the table operation_analytique @@ -247,7 +270,7 @@ class Anc_Operation } - $class=($count%2==0)?"odd":""; + $class=($count%2==0)?"odd":"even"; $count++; $cred= ( $row['oa_debit'] == 'f')?"CREDIT":"DEBIT"; $ret.=""; @@ -289,7 +312,7 @@ class Anc_Operation } /*!\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 @@ class Anc_Operation oa_group, oa_date, pa_id, - oa_row + oa_row, + oa_positive 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 @@ class Anc_Operation $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.=''; @@ -511,21 +535,100 @@ class Anc_Operation } $result.="
'.$value->input().'
"; - $style_remain=($remain==0)?'style="color:green"':' style="color:red"'; - $result.=" Reste à imputer = ". - ''. - $remain.''; - - // 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 ) + { + $style_remain=($remain==0)?'style="color:green"':' style="color:red"'; + $result.=" Reste à imputer = ". + ''. + $remain.''; + + // 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.="
".$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).'
'; */ + /* for each row */ + // for ($i=0;$idb); + $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 @@ class Anc_Operation $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 @@ class Anc_Operation */ 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;$edb->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 @@ class Anc_Operation $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_positive=='Y')?$p_array[$i]->oa_amount:($p_array[$i]->oa_amount*(-1)); } $result['val']=$val; return $result; diff --git a/include/class_anc_table.php b/include/class_anc_table.php index 952e1acb1..3adb313d5 100644 --- a/include/class_anc_table.php +++ b/include/class_anc_table.php @@ -144,7 +144,8 @@ class Anc_Table extends Anc_Acc_Link $tot_global=0; for ($i=0;$iarow);$i++) { - echo ''; + $tr=($i%2==0)?'':''; + echo $tr; echo td(HtmlInput::history_card($this->arow[$i]['f_id'],$this->arow[$i]['card_account'].' '.$this->arow[$i]['name'])); $tot_row=0; for ($x=0;$xaheader);$x++) @@ -197,8 +198,9 @@ class Anc_Table extends Anc_Acc_Link $tot_global=0; for ($i=0;$iarow);$i++) { - echo ''; - echo td(HtmlInput::history_account($this->arow[$i]['card_account'],$this->arow[$i]['card_account'].' '.$this->arow[$i]['name'])); + $tr=($i%2==0)?'':''; + echo $tr; + echo td(HtmlInput::history_account($this->arow[$i]['card_account'],$this->arow[$i]['card_account'].' '.$this->arow[$i]['name'])); $tot_row=0; for ($x=0;$xaheader);$x++) { diff --git a/include/class_document.php b/include/class_document.php index dbc87540e..cfe32c230 100644 --- a/include/class_document.php +++ b/include/class_document.php @@ -865,15 +865,17 @@ class Document // check if the march exists if (!isset(${$id})) $r= ""; - // check that something is sold - if (${'e_march' . $counter . '_price'} != 0 && ${'e_quant' . $counter} != 0) + else { - $f = new Fiche($this->db); - $f->get_by_qcode(${$id}, false); - $r = $f->strAttribut(ATTR_DEF_NAME); + // check that something is sold + if (${'e_march' . $counter . '_price'} != 0 && ${'e_quant' . $counter} != 0) + { + $f = new Fiche($this->db); + $f->get_by_qcode(${$id}, false); + $r = $f->strAttribut(ATTR_DEF_NAME); + } else + $r = ""; } - else - $r=""; } else $r=${'e_march'.$counter.'_label'}; diff --git a/include/constant.php b/include/constant.php index b1afdea8f..ce08c5134 100644 --- a/include/constant.php +++ b/include/constant.php @@ -71,7 +71,7 @@ define ("SITE_UPDATE",'http://www.phpcompta.eu/last_version.txt'); 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--'); diff --git a/include/template/anc_balance_group.php b/include/template/anc_balance_group.php index 1cb0ecfe3..d7c26e22b 100644 --- a/include/template/anc_balance_group.php +++ b/include/template/anc_balance_group.php @@ -51,7 +51,7 @@ if ( $prev != $array[$i]['ga_id']) '; + echo ''; else echo ''; echo td($array[$i]['po_name']); diff --git a/include/template/ledger_detail_ach.php b/include/template/ledger_detail_ach.php index 4b8ce7f4a..a21703f5d 100644 --- a/include/template/ledger_detail_ach.php +++ b/include/template/ledger_detail_ach.php @@ -128,6 +128,7 @@ if ($owner->MY_TVA_USE == 'Y') { echo th(_('HTVA'), 'style="text-align:right"'); + echo th(_('TVA ND'), 'style="text-align:right"'); echo th(_('TVA'), 'style="text-align:right"'); echo th(_('TVAC'), 'style="text-align:right"'); } else @@ -194,15 +195,15 @@ if ($owner->MY_TVA_USE == 'Y') { - $tva_amount = bcadd($q['qp_vat'], $q['qp_nd_tva']); - $tva_amount = bcadd($tva_amount, $q['qp_nd_tva_recup']); + $tva_amount_nd = bcadd($q['qp_nd_tva_recup'], $q['qp_nd_tva']); $class = ""; if ($q['qp_vat_sided'] <> 0) { $class = ' style="text-decoration:line-through"'; $tvac = bcsub($tvac, $q['qp_vat']); } - $row.=td(nbm($tva_amount), 'class="num" ' . $class); + $row.=td(nbm($tva_amount_nd), 'class="num" ' . $class); + $row.=td(nbm($q['qp_vat']), 'class="num" ' . $class); $row.=td(nbm($tvac), 'class="num"'); } $total_tvac+=$tvac; @@ -233,7 +234,7 @@ $row = td(_('Total'), ' style="font-style:italic;text-align:right;font-weight: bolder;width:auto" colspan="6"'); $row.=td(nbm($total_htva), 'class="num" style="font-style:italic;font-weight: bolder;"'); if ($owner->MY_TVA_USE == 'Y') - $row.=td("") . td(nbm($total_tvac), 'class="num" style="font-style:italic;font-weight: bolder;"'); + $row.=td("") . td("").td(nbm($total_tvac), 'class="num" style="font-style:italic;font-weight: bolder;"'); echo tr($row); ?> @@ -286,20 +287,25 @@ } else $view_history = ''; $row.=td($view_history); - /* $row=td($q[$e]['j_poste']); */ - /* $row.=td($q[$e]['j_qcode']); */ - if ($q[$e]['j_qcode'] != '') + + if ($q[$e]['j_text']=="") { + if ($q[$e]['j_qcode'] != '') + { // nom de la fiche - $ff = new Fiche($cn); - $ff->get_by_qcode($q[$e]['j_qcode']); - $row.=td($ff->strAttribut(h(ATTR_DEF_NAME))); - } else - { - // libellé du compte - $name = $cn->get_value('select pcm_lib from tmp_pcmn where pcm_val=$1', array($q[$e]['j_poste'])); - $row.=td(h($name)); + $ff = new Fiche($cn); + $ff->get_by_qcode($q[$e]['j_qcode']); + $row.=td($ff->strAttribut(h(ATTR_DEF_NAME))); + } else + { + // libellé du compte + $name = $cn->get_value('select pcm_lib from tmp_pcmn where pcm_val=$1', array($q[$e]['j_poste'])); + $row.=td(h($name)); + } } + else + $row.=td(h($q[$e]['j_text'])); + $montant = td(nbm($q[$e]['j_montant']), 'class="num"'); $row.=($q[$e]['j_debit'] == 't') ? $montant : td(''); $row.=($q[$e]['j_debit'] == 'f') ? $montant : td('');