diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 0dbf4b460..34daff0cb 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -346,7 +346,10 @@ $path = array( 'list_filter_followup'=>"ajax_follow_up", //delete a filter for followup 'delete_filter_followup'=>"ajax_follow_up", - "check_vatnumber"=>"ajax_check_vatnumber" + // Check VAT NUMBER with VIES European VAT + "check_vatnumber"=>"ajax_check_vatnumber", + // Tax Detail + "tax_detail"=>"ajax_tax_detail" ) ; if (array_key_exists($op, $path)) { diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js index 7ca3b0422..e0055181b 100644 --- a/html/js/acc_ledger.js +++ b/html/js/acc_ledger.js @@ -1731,7 +1731,56 @@ function duplicate_operation(p_dossier, p_jr_id) { } ); } +/** + * Go to detail of Tax for a specific period , ledger id and tva_id + */ +function tax_detail_view (dossier_id,date_from,date_to,nLedger_id,nTva_id) +{ + try + { + var dgbox="detail_tax_box"; + waiting_box(); + removeDiv(dgbox); + // For form , most of the parameters are in the FORM + // method is then POST + //var queryString=$(p_form_id).serialize(true); + + var queryString = { + op: 'tax_detail', + act: "tax_detail_view", + gDossier: dossier_id, + boxid: dgbox, + date_from:date_from, + date_to:date_to, + ledger_id:nLedger_id, + tva_id:nTva_id + }; + var action = new Ajax.Request( + "ajax_misc.php" , + { + method:'GET', + parameters:queryString, + onFailure:ajax_misc_failure, + onSuccess:function(req){ + remove_waiting_box(); + if (req.responseText == 'NOCONX') { + reconnect(); + return; + } + var y=calcy(15); + var div_style="position:absolute;"+";top:"+y+"px"; + add_div({id:dgbox,cssclass:'inner_box',html:loading(),style:div_style,drag:true}); + $(dgbox).update(req.responseText); + + } + } + ); + }catch( e) + { + alert_box(e.message); + } +} /** * For operation_exercice let update periode when changing folder * @type {{update_periode: operation_exercice.update_periode}} @@ -1959,7 +2008,7 @@ var operation_exercice = { return; } var answer=req.responseJSON; -console.debug(answer['content']); + $('operation_exercice_transfer_info').update(answer.content); diff --git a/include/ajax/ajax_tax_detail.php b/include/ajax/ajax_tax_detail.php new file mode 100644 index 000000000..a67f0884b --- /dev/null +++ b/include/ajax/ajax_tax_detail.php @@ -0,0 +1,60 @@ +get('tva_id') + ,$http->get("date_from",'date') + ,$http->get("date_to",'date') + ,$http->get("ledger_id",'number') + ); + $boxid=$http->get("boxid"); + +} catch (\Exception $e) { + echo $e->getMessage(); + return; +} +echo \HtmlInput::title_box("Détail TVA", $boxid); +?> +
+

+ Il peut y avoir des différences entre la TVA calculée et à récupérer à cause de TVA Non Déductible, reprise + à charge du gérant ou d'arrondi. +

+ html(); + ?> +
+ + diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index d9a5ff7af..61a883561 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -323,7 +323,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger } /** - * Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT + * @brief 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 diff --git a/include/class/tax_detail.class.php b/include/class/tax_detail.class.php new file mode 100644 index 000000000..98906b6c6 --- /dev/null +++ b/include/class/tax_detail.class.php @@ -0,0 +1,183 @@ +tva_code=$tva_code; + $this->from=$from; + $this->to=$to; + $this->ledger_id=$ledger_id; + + } + + /** + * @brief display a form for giving tva_code and dates + * @return void + */ + static function display_form() + { + require_once NOALYSS_TEMPLATE."/tax_detail-display_form.php"; + } + + /** + * @brief get data + */ + function get_data() + { + global $g_user,$cn; + $filter_ledger=" where "; + + + // Security + if ($g_user->get_status_security_ledger()==1 && $g_user->isAdmin()==0) { + $filter_ledger.=$g_user->get_ledger_sql('ALL')." and "; + } + + // filter on the date + $filter_ledger.=" jr_date >= to_date ($1,'DD.MM.YYYY') and jr_date <= to_date($2,'DD.MM.YYYY')"; + + // SQL index of array for array used in DatabaseCore::get_array + $param_idx=3; + $aParameter=array($this->from,$this->to); + + // filter on vat_code + if ( !empty($this->tva_code ) ) + { + $acc_tva=Acc_Tva::build($cn, $this->tva_code); + $filter_ledger.=" and tva_opid = \$$param_idx "; + $aParameter[]=$acc_tva->tva_id; + $param_idx++; + } + // filter on the ledger + if ( $this->ledger_id <> -1 ) { + $filter_ledger.= " and jr_def_id = \$$param_idx"; + $param_idx++; + $aParameter[]=$this->ledger_id; + + } + $sql=" +with v_amount_tva as (select + f_id + ,j_qcode + ,case when j_debit is true then 0-j_montant else j_montant end j_montant + , qp_vat_code tva_opid + , 0-qp_nd_tva qp_nd_tva + , 0-qp_nd_tva_recup qp_nd_tva_recup + , 0-qp_dep_priv qp_dep_priv + , qp_vat_sided + , j_poste + , j_debit + , j_text + , jr2.jr_id + , jr2.jr_pj_number + , jr2.jr_internal + ,jr2.jr_date + ,to_char(jr2.jr_date,'DD.MM.YY') str_date + ,jr_def_id + ,0-qp_vat vat_amount + from jrnx jr1 + join jrn jr2 on (jr1.j_grpt = jr2.jr_grpt_id) + join quant_purchase q1 using (j_id) + union all + select f_id + ,j_qcode + ,case when j_debit is true then 0-j_montant else j_montant end + , qs_vat_code + , 0 + , 0 + , 0 + , 0 + , j_poste + , j_debit + , j_text + , jr4.jr_id + , jr4.jr_pj_number + , jr4.jr_internal + ,jr4.jr_date + ,to_char(jr4.jr_date,'DD.MM.YY') + ,jr_def_id + ,qs_vat + from jrnx jr3 + join jrn jr4 on (jr3.j_grpt = jr4.jr_grpt_id) + join quant_sold qs using (j_id) + ) +select *, tva_label,format ('%s (%s)',t1.tva_code ,t1.tva_label) tva_code,tva_rate +from v_amount_tva v1 +join tva_rate t1 on (v1.tva_opid=t1.tva_id) +$filter_ledger +order by jr_date,j_debit + "; + $data=$cn->get_array($sql,$aParameter); + return $data; + } + /** + * @brief display the result in HTML + * @return void + */ + function html() { + global $data; + $data=$this->get_data(); + require NOALYSS_TEMPLATE."/tax_detail-html.php"; + } + function button_export_csv() + { + require NOALYSS_TEMPLATE."/tax_detail-button_export_csv.php"; + } + + /** + * @brief export the result in a CSV file + */ + function csv() { + $noalyss_csv=new Noalyss_Csv(sprintf("tax_detail-{$this->tva_code}-{$this->from}-{$this->to}")); + $data=$this->get_data(); + + $header=["date",'piece',"fiche","poste","base","privé","code tva","taux","montant tva","non deductible","recup"]; + $noalyss_csv->send_header(); + $noalyss_csv->write_header($header ); + foreach ($data as $item) { + + $noalyss_csv->add($item['str_date']); + $noalyss_csv->add($item['jr_pj_number']); + $noalyss_csv->add($item['jr_internal']); + $noalyss_csv->add($item['j_qcode']); + $noalyss_csv->add($item['j_poste']); + $noalyss_csv->add(nb($item['j_montant'],2),"number"); + $noalyss_csv->add(nb($item['qp_dep_priv'],2),"number"); + $noalyss_csv->add($item['tva_code']); + $noalyss_csv->add(nb($item['tva_rate'],2),"number"); + $noalyss_csv->add(nb($item['vat_amount'],2),"number"); + $noalyss_csv->add(nb($item['qp_nd_tva'],2),"number"); + $noalyss_csv->add(nb($item['qp_nd_tva_recup'],2),"number"); + $noalyss_csv->write(); + + } + } +} \ No newline at end of file diff --git a/include/class/tax_summary.class.php b/include/class/tax_summary.class.php index ffb5e5037..7417034ff 100644 --- a/include/class/tax_summary.class.php +++ b/include/class/tax_summary.class.php @@ -67,7 +67,6 @@ class Tax_Summary public function get_db() { return $this->db; - return $this; } /** @@ -85,7 +84,6 @@ class Tax_Summary public function get_date_start() { return $this->date_start; - return $this; } /** @@ -105,7 +103,7 @@ class Tax_Summary public function get_date_end() { return $this->date_end; - return $this; + } /** @@ -240,9 +238,9 @@ class Tax_Summary return $sql; } /** - * Build the SQL for sale vat + * @brief Build the SQL for sale vat * - * @param group by ledger + * @param $p_group_ledger bool true group by ledgers * * @return string * @@ -329,12 +327,13 @@ class Tax_Summary amount_vat, amount_wovat, amount_sided, - tva_payment_sale as tva_type + tva_payment_sale as tva_type, + jrn_def.jrn_def_id from detail_tva join tva_rate on (tva_rate.tva_id=qs_vat_code) join jrn_def on (jrn_def.jrn_def_id=j_jrn_def) - order by jrn_def_name, tva_code ||' ('||tva_rate.tva_label||')'"; + order by jrn_def.jrn_def_id,jrn_def_name, tva_code ||' ('||tva_rate.tva_label||')'"; $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]); return $array; @@ -358,12 +357,13 @@ class Tax_Summary amount_noded_amount, amount_noded_tax, amount_noded_return, - amount_private + amount_private, + jrn_def.jrn_def_id from detail_tva join tva_rate on (tva_rate.tva_id=qp_vat_code) join jrn_def on (jrn_def.jrn_def_id=j_jrn_def) - order by jrn_def_name, tva_code ||' ('||tva_rate.tva_label||')'"; + order by jrn_def.jrn_def_id,jrn_def_name, tva_code ||' ('||tva_rate.tva_label||')'"; $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]); return $array; } @@ -392,7 +392,7 @@ class Tax_Summary } /** - * Summary for all purchase ledger + * @brief Summary for all purchase ledgers */ function get_summary_purchase() { @@ -464,4 +464,24 @@ class Tax_Summary echo ''; } + /** + * @brief Build a link to show the detail of a VAT ID + * @param $dateStart date from format 'DD.MM.YYYY' + * @param $DateeEd date to format 'DD.MM.YYYY' + * @param $nLedger_id integer JRN_DEF.JRN_DEF_ID + * @param $nVAT_id integer TVA_RATE.TVA_ID + * @return javascript string + */ + function build_link_detail($dossier_id,$dateStart,$DateeEd,$nLedger_id,$nVAT_id) + { + + + $js=sprintf("tax_detail_view('%s','%s','%s','%s','%s')", + $dossier_id,$this->date_start,$this->date_end,$nLedger_id,$nVAT_id); + + return $js; + + + } + } diff --git a/include/export/export_p1tva_csv.php b/include/export/export_p1tva_csv.php new file mode 100644 index 000000000..8688f4f6e --- /dev/null +++ b/include/export/export_p1tva_csv.php @@ -0,0 +1,40 @@ +get("vat_code"), + $http->get("from"), + $http->get("to"), + $http->get("p_jrn") + ); +} catch (\Exception $e) { + echo $e->getMessage(); + return; +} + +$tax_detail->csv(); \ No newline at end of file diff --git a/include/tax_detail.inc.php b/include/tax_detail.inc.php new file mode 100644 index 000000000..f6babd2cf --- /dev/null +++ b/include/tax_detail.inc.php @@ -0,0 +1,41 @@ +get("vat_code"), + $http->get("from","date"), + $http->get("to","date"), + $http->get("p_jrn","number")); + $tax_detail->button_export_csv(); + $tax_detail->html(); + $tax_detail->button_export_csv(); + +} diff --git a/include/template/tax_detail-button_export_csv.php b/include/template/tax_detail-button_export_csv.php new file mode 100644 index 000000000..d5277b1cb --- /dev/null +++ b/include/template/tax_detail-button_export_csv.php @@ -0,0 +1,41 @@ + + diff --git a/include/template/tax_detail-display_form.php b/include/template/tax_detail-display_form.php new file mode 100644 index 000000000..31c5f2fac --- /dev/null +++ b/include/template/tax_detail-display_form.php @@ -0,0 +1,85 @@ +value=$http->get("vat_code","string",""); +$idatestart = new IDate("from"); +$idateend = new IDate("to"); + +global $g_user, $http; + +$a_limit = $g_user->get_limit_current_exercice(); +$idatestart->value = $http->get('from', 'date', $a_limit[0]); +$idateend->value = $http->get('to', 'date', $a_limit[1]); + + +?> +
+

+ Il peut y avoir des différences entre la TVA calculée et à récupérer à cause de TVA Non Déductible, reprise + à charge du gérant ou d'arrondi. +

+
+
+ + input(); ?> + + input(); ?> + + + input(); ?> + + get_ledger('ACH',3); + $a_ledger_sale=$g_user->get_ledger('VEN',3); + $a_ledger=array_merge($a_ledger_sale,$a_ledger_purchase); + if ( DEBUGNOALYSS > 1 ) echo \Noalyss\Dbg::hidden_info("a_ledger",$a_ledger); + $select_value=array(); + $select_value[]=array('value'=>-1,"label"=>'Tous vente et Achat'); + foreach($a_ledger as $i_ledger) : + $select_value[]=array("value"=>$i_ledger["jrn_def_id"],"label"=>$i_ledger['jrn_def_name']); + endforeach; + $select=new \ISelect("p_jrn"); + $select->value=$select_value; + $select->selected=$http->get("p_jrn","number",-1); + echo $select->input(); + ?> +
+ + + + request("ac")); + echo \Dossier::hidden(); + ?> +
+ +
+
\ No newline at end of file diff --git a/include/template/tax_detail-html.php b/include/template/tax_detail-html.php new file mode 100644 index 000000000..a235d5e17 --- /dev/null +++ b/include/template/tax_detail-html.php @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + diff. TVA calculée %s',$delta_control); + } +?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DatePièceFichePosteBasecode TVATauxMontant TVANon déductiblerécupérable par impôtAutoliquidation
+ +
diff --git a/include/template/tax_summary_display.php b/include/template/tax_summary_display.php index 4f7bcdb79..11a6640b6 100644 --- a/include/template/tax_summary_display.php +++ b/include/template/tax_summary_display.php @@ -33,6 +33,7 @@ bcscale(4); $array=$this->get_row_sale(); $nb_array=count($array); +$dossier_id=Dossier::id(); $ledger=""; $r=0; $tot_vat=0;$tot_wovat=0;$tot_sided=0; @@ -71,8 +72,13 @@ for ($i=0;$i < $nb_array;$i++): + build_link_detail($dossier_id, $this->date_start, $this->date_end,$array[$i]['jrn_def_id'], $array[$i]['qs_vat_code']); + ?> + Détails - + % @@ -143,6 +149,7 @@ $a_sum=$this->get_summary_sale(); + % @@ -224,6 +231,11 @@ for ($i=0;$i < $nb_array;$i++): + build_link_detail($dossier_id, $this->date_start, $this->date_end,$array[$i]['jrn_def_id'], $array[$i]['qp_vat_code']); + ?> + Détails % diff --git a/sql/upgrade.sql b/sql/upgrade.sql index e69de29bb..85ba072d6 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -0,0 +1,44 @@ +CREATE OR REPLACE FUNCTION replace_menu_code( code_source text, code_destination text) + RETURNS void +AS $function$ +begin + /*code */ + + update bookmark set b_action = replace(b_action,code_source,code_destination) where b_action ~ code_source; + update menu_ref set me_code =code_destination where me_code = code_source; + update profile_menu set me_code=code_destination where me_code = code_source; + update profile_menu set me_code_dep=code_destination where me_code_dep = code_source; +end ; +$function$ +LANGUAGE plpgsql; + + +select replace_menu_code('PRINTGL','P0GRL'); +select replace_menu_code('PRINTBAL','P0BAL'); +select replace_menu_code('PRINTREC','P0RAP'); +select replace_menu_code('PRINTBILAN','P0BIL'); +select replace_menu_code('PRINTJRN','P0JRN'); +select replace_menu_code('PRINTTVA','P0TVA'); +select replace_menu_code('PRINTPOSTE','P0PST'); +select replace_menu_code('PRINTREPORT','P0RPO'); +select replace_menu_code('BALAGE','P0BLG'); + + +insert into menu_ref (me_code,me_menu,me_file,me_description,me_type,me_description_etendue) +values('P1TVA','Détail TVA','tax_detail.inc.php','Détail TVA par journal','ME','Détail des TVA '); + +insert into profile_menu (me_code,me_code_dep,p_id,p_order,p_type_display,pm_default,pm_id_dep) +select me_code,'PRINT',1,250,'E',0,6 from menu_ref where me_code='P1TVA' +union +select me_code,'PRINT',1,250,'E',0,35 from menu_ref where me_code='P1TVA' +union +select me_code,'PRINT',2,250,'E',0,719 from menu_ref where me_code='P1TVA' and exists (select 1 from profile where p_id=2) +union +select me_code,'PRINT',2,250,'E',0,716 from menu_ref where me_code='P1TVA' and exists (select 1 from profile where p_id=2) +; +insert into menu_ref (me_code,me_menu,me_file,me_type) +values ('CSV:p1tva','Export Détail TVA','export_p1tva_csv.php','PR') + +; + +insert into profile_menu(me_code,p_id,p_type_display) select 'CSV:p1tva',p_id,'P' from profile where p_id in (1,2); \ No newline at end of file