diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index f38f7e72aa2..70808920d49 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2011-2014 Alexandre Spangaro + * Copyright (C) 2011-2014 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -353,6 +354,108 @@ if ($conf->tax->enabled) } } } +//localtax +if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") +{ + $j=1; + $numlt=3; +} +elseif($mysoc->localtax1_assuj=="1") +{ + $j=1; + $numlt=2; +} +elseif($mysoc->localtax2_assuj=="1") +{ + $j=2; + $numlt=3; +} +else +{ + $j=0; + $numlt=0; +} + +while($j<$numlt) +{ + if (empty($_GET["mode"]) || $_GET["mode"] != 'sconly') + { + print "
"; + + $tva = new Tva($db); + + print_fiche_titre($langs->transcountry(($j==1?"LT1Payments":"LT2Payments"),$mysoc->country_code).($year?' ('.$langs->trans("Year").' '.$year.')':''), '', ''); + + + $sql = "SELECT pv.rowid, pv.amount, pv.label, pv.datev as dm, pv.datep as dp"; + $sql.= " FROM ".MAIN_DB_PREFIX."localtax as pv"; + $sql.= " WHERE pv.entity = ".$conf->entity." AND localtaxtype = ".$j ; + if ($year > 0) + { + // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, + // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire + $sql.= " AND pv.datev between '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; + } + if (preg_match('/^pv/',$sortfield)) $sql.= $db->order($sortfield,$sortorder); + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + $total = 0 ; + print ''; + print ''; + print_liste_field_titre($langs->trans("PeriodEndDate"),$_SERVER["PHP_SELF"],"pv.datev","",$param,'width="120"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"pv.label","",$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("ExpectedToPay"),$_SERVER["PHP_SELF"],"pv.amount","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("RefPayment"),$_SERVER["PHP_SELF"],"pv.rowid","",$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"pv.datep","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"pv.amount","",$param,'align="right"',$sortfield,$sortorder); + print "\n"; + $var=1; + while ($i < $num) + { + $obj = $db->fetch_object($result); + + $total = $total + $obj->amount; + + $var=!$var; + print ""; + print ''."\n"; + + print "\n"; + + print '"; + + // Ref payment + $tva_static->id=$obj->rowid; + $tva_static->ref=$obj->rowid; + print '\n"; + + print '\n"; + print '"; + print "\n"; + + $i++; + } + print ''; + print '"; + print ''; + print ''; + print '"; + print ""; + + print "
'.dol_print_date($db->jdate($obj->dm),'day').'".$obj->label."'.price($obj->amount)."'.$tva_static->getNomUrl(1)."'.dol_print_date($db->jdate($obj->dp),'day')."'.price($obj->amount)."
'.$langs->trans("Total").''.price($total)."  '.price($total)."
"; + $db->free($result); + } + else + { + dol_print_error($db); + } + } + $j++; +} llxFooter(); diff --git a/htdocs/compta/journal/purchasesjournal.php b/htdocs/compta/journal/purchasesjournal.php index 52562ed0244..7d1c9fa2777 100644 --- a/htdocs/compta/journal/purchasesjournal.php +++ b/htdocs/compta/journal/purchasesjournal.php @@ -1,7 +1,7 @@ * Copyright (C) 2007-2010 Jean Heimburger - * Copyright (C) 2011-2013 Juanjo Menent + * Copyright (C) 2011-2014 Juanjo Menent * Copyright (C) 2012 Regis Houssin * Copyright (C) 2011-2012 Alexandre spangaro * Copyright (C) 2013 Marcos García @@ -150,9 +150,9 @@ if ($result) $compta_localtax1 = (! empty($obj->account_localtax1)?$obj->account_localtax1:$langs->trans("CodeNotDef")); $compta_localtax2 = (! empty($obj->account_localtax2)?$obj->account_localtax2:$langs->trans("CodeNotDef")); - $account_localtax1=getLocalTaxesFromRate($obj->tva_tx, 1, $mysoc); + $account_localtax1=getLocalTaxesFromRate($obj->tva_tx, 1, $mysoc, $obj->thirdparty); $compta_localtax1= (! empty($account_localtax1[2])?$account_localtax1[2]:$langs->trans("CodeNotDef")); - $account_localtax2=getLocalTaxesFromRate($obj->tva_tx, 2, $mysoc); + $account_localtax2=getLocalTaxesFromRate($obj->tva_tx, 2, $mysoc, $obj->thirdparty); $compta_localtax2= (! empty($account_localtax2[2])?$account_localtax2[2]:$langs->trans("CodeNotDef")); $tabfac[$obj->rowid]["date"] = $obj->datef; diff --git a/htdocs/compta/journal/sellsjournal.php b/htdocs/compta/journal/sellsjournal.php index 931b8757470..c3f276ca956 100644 --- a/htdocs/compta/journal/sellsjournal.php +++ b/htdocs/compta/journal/sellsjournal.php @@ -1,7 +1,7 @@ * Copyright (C) 2007-2010 Jean Heimburger - * Copyright (C) 2011-2013 Juanjo Menent + * Copyright (C) 2011-2014 Juanjo Menent * Copyright (C) 2012 Regis Houssin * Copyright (C) 2011-2012 Alexandre Spangaro * Copyright (C) 2013 Marcos García @@ -153,9 +153,9 @@ if ($result) $cpttva = (! empty($conf->global->COMPTA_VAT_ACCOUNT)?$conf->global->COMPTA_VAT_ACCOUNT:$langs->trans("CodeNotDef")); $compta_tva = (! empty($obj->account_tva)?$obj->account_tva:$cpttva); - $account_localtax1=getLocalTaxesFromRate($obj->tva_tx, 1, $mysoc); + $account_localtax1=getLocalTaxesFromRate($obj->tva_tx, 1, $obj->thirdparty, $mysoc); $compta_localtax1= (! empty($account_localtax1[3])?$account_localtax1[3]:$langs->trans("CodeNotDef")); - $account_localtax2=getLocalTaxesFromRate($obj->tva_tx, 2, $mysoc); + $account_localtax2=getLocalTaxesFromRate($obj->tva_tx, 2, $obj->thirdparty, $mysoc); $compta_localtax2= (! empty($account_localtax2[3])?$account_localtax2[3]:$langs->trans("CodeNotDef")); //la ligne facture diff --git a/htdocs/compta/localtax/class/localtax.class.php b/htdocs/compta/localtax/class/localtax.class.php index b500a701254..bda3150937e 100644 --- a/htdocs/compta/localtax/class/localtax.class.php +++ b/htdocs/compta/localtax/class/localtax.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2014 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ class Localtax extends CommonObject { var $id; var $ref; + var $ltt; var $tms; var $datep; var $datev; @@ -74,6 +75,7 @@ class Localtax extends CommonObject // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."localtax("; + $sql.= "localtaxtype,"; $sql.= "tms,"; $sql.= "datep,"; $sql.= "datev,"; @@ -84,6 +86,7 @@ class Localtax extends CommonObject $sql.= "fk_user_creat,"; $sql.= "fk_user_modif"; $sql.= ") VALUES ("; + $sql.= " ".$this->ltt.","; $sql.= " '".$this->db->idate($this->tms)."',"; $sql.= " '".$this->db->idate($this->datep)."',"; $sql.= " '".$this->db->idate($this->datev)."',"; @@ -141,6 +144,7 @@ class Localtax extends CommonObject // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."localtax SET"; + $sql.= " localtaxtype=".$this->ltt.","; $sql.= " tms=".$this->db->idate($this->tms).","; $sql.= " datep=".$this->db->idate($this->datep).","; $sql.= " datev=".$this->db->idate($this->datev).","; @@ -186,6 +190,7 @@ class Localtax extends CommonObject global $langs; $sql = "SELECT"; $sql.= " t.rowid,"; + $sql.= " t.localtaxtype,"; $sql.= " t.tms,"; $sql.= " t.datep,"; $sql.= " t.datev,"; @@ -212,6 +217,7 @@ class Localtax extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->rowid; + $this->ltt = $obj->localtaxtype; $this->tms = $this->db->jdate($obj->tms); $this->datep = $this->db->jdate($obj->datep); $this->datev = $this->db->jdate($obj->datev); @@ -285,6 +291,7 @@ class Localtax extends CommonObject $this->id=0; $this->tms=''; + $this->ltt=0; $this->datep=''; $this->datev=''; $this->amount=''; @@ -476,12 +483,12 @@ class Localtax extends CommonObject } // Insertion dans table des paiement localtax - $sql = "INSERT INTO ".MAIN_DB_PREFIX."localtax (datep, datev, amount"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."localtax (localtaxtype, datep, datev, amount"; if ($this->note) $sql.=", note"; if ($this->label) $sql.=", label"; $sql.= ", fk_user_creat, fk_bank"; $sql.= ") "; - $sql.= " VALUES ('".$this->db->idate($this->datep)."',"; + $sql.= " VALUES (".$this->ltt.", '".$this->db->idate($this->datep)."',"; $sql.= "'".$this->db->idate($this->datev)."'," . $this->amount; if ($this->note) $sql.=", '".$this->db->escape($this->note)."'"; if ($this->label) $sql.=", '".$this->db->escape($this->label)."'"; diff --git a/htdocs/compta/localtax/clients.php b/htdocs/compta/localtax/clients.php index cc71b402060..a75d48385cb 100644 --- a/htdocs/compta/localtax/clients.php +++ b/htdocs/compta/localtax/clients.php @@ -1,6 +1,6 @@ - * Copyright (C) 2014 Ferran Marcet +/* Copyright (C) 2011-2014 Juanjo Menent + * Copyright (C) 2014 Ferran Marcet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,8 @@ $langs->load("compta"); $langs->load("companies"); $langs->load("products"); +$local=GETPOST('localTaxType', 'int'); + // Date range $year=GETPOST("year"); if (empty($year)) @@ -102,12 +104,14 @@ $fsearch.=' '; $fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': '; $fsearch.=' '; +$calc=MAIN_INFO_LOCALTAX_CALC.$local; // Affiche en-tete du rapport -if ($modetax==1) // Calculate on invoice for goods and services +if ($conf->global->$calc==0 || $conf->global->$calc==1) // Calculate on invoice for goods and services { - $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->country_code); + $nom=$langs->transcountry($local==1?"LT1ReportByCustomersInInputOutputMode":"LT2ReportByCustomersInInputOutputMode",$mysoc->country_code); + $calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT'.$local.'Rec"); + $calcmode.='
('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/taxes.php').')'; $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); - $description=$langs->trans("RulesVATDue"); if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='
'.$langs->trans("WarningDepositsNotIncluded"); $description.=$fsearch; $description.='
('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')'; @@ -120,11 +124,12 @@ if ($modetax==1) // Calculate on invoice for goods and services $productsup=$langs->trans("Description"); $amountsup=$langs->trans("AmountHT"); } -if ($modetax==0) // Invoice for goods, payment for services +if ($conf->global->$calc==2) // Invoice for goods, payment for services { - $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->country_code); + $nom=$langs->transcountry($local==1?"LT1ReportByCustomersInInputOutputMode":"LT2ReportByCustomersInInputOutputMode",$mysoc->country_code); + $calcmode=$langs->trans("CalcModeLT2Debt"); + $calcmode.='
('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/taxes.php').')'; $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); - $description=$langs->trans("RulesVATIn"); if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='
'.$langs->trans("WarningDepositsNotIncluded"); $description.=$fsearch; $description.='
('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')'; @@ -137,173 +142,179 @@ if ($modetax==0) // Invoice for goods, payment for services $productsup=$langs->trans("Description"); $amountsup=$langs->trans("AmountHT"); } -report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); +report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode); -$vatcust=$langs->transcountry("LT2",$mysoc->country_code); -$vatsup=$langs->transcountry("LT2",$mysoc->country_code); + +$vatcust=$langs->transcountry($local==1?"LT1":"LT2",$mysoc->country_code); +$vatsup=$langs->transcountry($local==1?"LT1":"LT2",$mysoc->country_code); // IRPF that the customer has retained me +if($conf->global->$calc ==0 || $conf->global->$calc == 2){ + print ""; + print ""; + print '"; + print '"; + print ""; + print ""; + print ""; + print "\n"; -print "
'.$langs->trans("Num")."'.$langs->trans("Customer")."".$langs->transcountry("ProfId1",$mysoc->country_code)."".$langs->trans("TotalHT")."".$vatcust."
"; -print ""; -print '"; -print '"; -print ""; -print ""; -print ""; -print "\n"; - -$coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell'); - -$action = "tvaclient"; -$object = &$coll_list; -$parameters["mode"] = $modetax; -$parameters["start"] = $date_start; -$parameters["end"] = $date_end; -$parameters["direction"] = 'sell'; -// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array -$hookmanager->initHooks(array('externalbalance')); -$reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks - -if (is_array($coll_list)) -{ - $var=true; - $total = 0; $totalamount = 0; - $i = 1; - foreach($coll_list as $coll) + $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell'); + + $action = "tvaclient"; + $object = &$coll_list; + $parameters["mode"] = $modetax; + $parameters["start"] = $date_start; + $parameters["end"] = $date_end; + $parameters["direction"] = 'sell'; + // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array + $hookmanager->initHooks(array('externalbalance')); + $reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + + if (is_array($coll_list)) { - if(($min == 0 or ($min > 0 && $coll->amount > $min)) && $coll->localtax2!=0) + $var=true; + $total = 0; $totalamount = 0; + $i = 1; + foreach($coll_list as $coll) { - $var=!$var; - $intra = str_replace($find,$replace,$coll->tva_intra); - if(empty($intra)) + if(($min == 0 or ($min > 0 && $coll->amount > $min)) && ($local==1?$coll->localtax1:$coll->localtax2) !=0) { - if($coll->assuj == '1') + $var=!$var; + $intra = str_replace($find,$replace,$coll->tva_intra); + if(empty($intra)) { - $intra = $langs->trans('Unknown'); - } - else - { - $intra = ''; + if($coll->assuj == '1') + { + $intra = $langs->trans('Unknown'); + } + else + { + $intra = ''; + } } + print ""; + print '"; + $company_static->id=$coll->socid; + $company_static->nom=$coll->nom; + print ''; + $find = array(' ','.'); + $replace = array('',''); + print '"; + print ""; + print ""; + $totalamount = $totalamount + $coll->amount; + $total = $total + ($local==1?$coll->localtax1:$coll->localtax2); + print "\n"; + $i++; } - print ""; - print '"; - $company_static->id=$coll->socid; - $company_static->nom=$coll->nom; - print ''; - $find = array(' ','.'); - $replace = array('',''); - print '"; - print ""; - print ""; - $totalamount = $totalamount + $coll->amount; - $total = $total + $coll->localtax2; - print "\n"; - $i++; } + $x_coll_sum = $total; + + print ''; + print ''; + print ''; + print ''; } - $x_coll_sum = $total; - - print ''; - print ''; - print ''; - print ''; -} -else -{ - $langs->load("errors"); - if ($coll_list == -1) - print ''; - else if ($coll_list == -2) - print ''; else - print ''; + { + $langs->load("errors"); + if ($coll_list == -1) + print ''; + else if ($coll_list == -2) + print ''; + else + print ''; + } } // IRPF I retained my supplier +if($conf->global->$calc ==0 || $conf->global->$calc == 1){ + print "
'.$langs->trans("Num")."'.$langs->trans("Customer")."".$langs->transcountry("ProfId1",$mysoc->country_code)."".$langs->trans("TotalHT")."".$vatcust."
'.$i."'.$company_static->getNomUrl(1).''.$intra."".price($coll->amount)."".price($local==1?$coll->localtax1:$coll->localtax2)."
'.$i."'.$company_static->getNomUrl(1).''.$intra."".price($coll->amount)."".price($coll->localtax2)."
'.$langs->trans("Total").':'.price($totalamount).''.price($total).'
'.$langs->trans("Total").':'.price($totalamount).''.price($total).'
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("Error").'
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("Error").'
"; + print ""; + print '"; + print '"; + print ""; + print ""; + print ""; + print "\n"; -print ""; -print '"; -print '"; -print ""; -print ""; -print ""; -print "\n"; - -$company_static=new Societe($db); - -$coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy'); -$parameters["direction"] = 'buy'; -$reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks -if (is_array($coll_list)) -{ - $var=true; - $total = 0; $totalamount = 0; - $i = 1; - foreach($coll_list as $coll) + $company_static=new Societe($db); + + $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy'); + $parameters["direction"] = 'buy'; + $reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + if (is_array($coll_list)) { - if(($min == 0 or ($min > 0 && $coll->amount > $min)) && $coll->localtax2!=0) + $var=true; + $total = 0; $totalamount = 0; + $i = 1; + foreach($coll_list as $coll) { - $var=!$var; - $intra = str_replace($find,$replace,$coll->tva_intra); - if(empty($intra)) + if(($min == 0 or ($min > 0 && $coll->amount > $min)) && ($local==1?$coll->localtax1:$coll->localtax2) != 0) { - if($coll->assuj == '1') + $var=!$var; + $intra = str_replace($find,$replace,$coll->tva_intra); + if(empty($intra)) { - $intra = $langs->trans('Unknown'); - } - else - { - $intra = ''; + if($coll->assuj == '1') + { + $intra = $langs->trans('Unknown'); + } + else + { + $intra = ''; + } } + print ""; + print '"; + $company_static->id=$coll->socid; + $company_static->nom=$coll->nom; + print ''; + $find = array(' ','.'); + $replace = array('',''); + print '"; + print ""; + print ""; + $totalamount = $totalamount + $coll->amount; + $total = $total + ($local==1?$coll->localtax1:$coll->localtax2); + print "\n"; + $i++; } - print ""; - print '"; - $company_static->id=$coll->socid; - $company_static->nom=$coll->nom; - print ''; - $find = array(' ','.'); - $replace = array('',''); - print '"; - print ""; - print ""; - $totalamount = $totalamount + $coll->amount; - $total = $total + $coll->localtax2; - print "\n"; - $i++; } + $x_paye_sum = $total; + + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Num")."'.$langs->trans("Supplier")."".$langs->transcountry("ProfId1",$mysoc->country_code)."".$langs->trans("TotalHT")."".$vatsup."
'.$langs->trans("Num")."'.$langs->trans("Supplier")."".$langs->transcountry("ProfId1",$mysoc->country_code)."".$langs->trans("TotalHT")."".$vatsup."
'.$i."'.$company_static->getNomUrl(1).''.$intra."".price($coll->amount)."".price($local==1?$coll->localtax1:$coll->localtax2)."
'.$i."'.$company_static->getNomUrl(1).''.$intra."".price($coll->amount)."".price($coll->localtax2)."
'.$langs->trans("Total").':'.price($totalamount).''.price($total).'
'; + } - $x_paye_sum = $total; - - print ''.$langs->trans("Total").':'; - print ''.price($totalamount).''; - print ''.price($total).''; - print ''; - - print ''; - - // Total to pay - print '

'; - print ''; - $diff = $x_paye_sum; - print ''; - print ''; - print '\n"; - print "\n"; - -} -else -{ - $langs->load("errors"); - if ($coll_list == -1) - print ''; - else if ($coll_list == -2) - print ''; else - print ''; + { + $langs->load("errors"); + if ($coll_list == -1) + print ''; + else if ($coll_list == -2) + print ''; + else + print ''; + } } +if($conf->global->$calc ==0){ + // Total to pay + print '

'; + print '
'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').''.price(price2num($diff,'MT'))."
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("Error").'
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("Error").'
'; + $diff = $x_coll_sum - $x_paye_sum ; + print ''; + print ''; + print '\n"; + print "\n"; + +} print '
'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').''.price(price2num($diff,'MT'))."
'; diff --git a/htdocs/compta/localtax/fiche.php b/htdocs/compta/localtax/fiche.php index c8849ba07f9..ec40eba55b9 100644 --- a/htdocs/compta/localtax/fiche.php +++ b/htdocs/compta/localtax/fiche.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2014 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ $langs->load("banks"); $langs->load("bills"); $id=$_REQUEST["id"]; - +$lttype=GETPOST('localTaxType', 'int'); $mesg = ''; // Security check @@ -44,6 +44,11 @@ $result = restrictedArea($user, 'tax', '', '', 'charges'); */ //add payment of localtax +if($_POST["cancel"] == $langs->trans("Cancel")){ + header("Location: reglement.php?localTaxType=".$lttype); + exit; +} + if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) { $localtax = new Localtax($db); @@ -59,12 +64,13 @@ if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) $localtax->datep=$datep; $localtax->amount=$_POST["amount"]; $localtax->label=$_POST["label"]; + $localtax->ltt=$lttype; $ret=$localtax->addPayment($user); if ($ret > 0) { $db->commit(); - header("Location: reglement.php"); + header("Location: reglement.php?localTaxType=".$lttype); exit; } else @@ -145,10 +151,11 @@ if ($_GET["action"] == 'create') { print "
\n"; print ''; + print ''; print ''; - print_fiche_titre($langs->transcountry("newLT2Payment",$mysoc->country_code)); - + print_fiche_titre($langs->transcountry($lttype==2?"newLT2Payment":"newLT1Payment",$mysoc->country_code)); + if ($mesg) print $mesg; print ''; @@ -163,7 +170,7 @@ if ($_GET["action"] == 'create') print ''; // Label - print ''; + print ''; // Amount print ''; diff --git a/htdocs/compta/localtax/index.php b/htdocs/compta/localtax/index.php index 5a832b7631b..67b33a65cec 100644 --- a/htdocs/compta/localtax/index.php +++ b/htdocs/compta/localtax/index.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2014 Juanjo Menent * Copyright (C) 2014 Ferran Marcet * * This program is free software; you can redistribute it and/or modify @@ -27,6 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $langs->load("other"); +$localTaxType=GETPOST('localTaxType', 'int'); $year=$_GET["year"]; if ($year == 0 ) @@ -95,13 +96,30 @@ function pt ($db, $sql, $date) llxHeader(); -$tva = new Tva($db); +if($localTaxType==1) +{ + $LT='LT1'; + $LTSummary='LT1Summary'; + $LTPaid='LT1Paid'; + $LTCustomer='LT1Customer'; + $LTSupplier='LT1Supplier'; + $CalcLT= $conf->global->MAIN_INFO_LOCALTAX_CALC1; +} +else +{ + $LT='LT2'; + $LTSummary='LT2Summary'; + $LTPaid='LT2Paid'; + $LTCustomer='LT2Customer'; + $LTSupplier='LT2Supplier'; + $CalcLT= $conf->global->MAIN_INFO_LOCALTAX_CALC2; +} -$textprevyear="".img_previous().""; -$textnextyear=" ".img_next().""; +$textprevyear="".img_previous().""; +$textnextyear=" ".img_next().""; -print_fiche_titre($langs->transcountry("LT2",$mysoc->country_code),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear"); +print_fiche_titre($langs->transcountry($LT,$mysoc->country_code),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear"); print $langs->trans("VATReportBuildWithOptionDefinedInModule").'
'; print '('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')
'; @@ -109,10 +127,10 @@ print '
'; print '
'.$langs->trans("Label").'transcountry("LT2Payment",$mysoc->country_code)).'">
'.$langs->trans("Label").'transcountry(($lttype==2?"LT2Payment":"LT1Payment"),$mysoc->country_code)).'">
'.$langs->trans("Amount").'
'; print ''; print '
'; -print_titre($langs->transcountry("LT2Summary",$mysoc->country_code)); +print_titre($langs->transcountry($LTSummary,$mysoc->country_code)); print ' '; -print_titre($langs->transcountry("LT2Paid",$mysoc->country_code)); +print_titre($langs->transcountry($LTPaid,$mysoc->country_code)); print '
'; @@ -120,8 +138,20 @@ print '
'; print ""; print ""; print ""; -print ""; -print ""; +if($CalcLT==0) +{ + print ""; + print ""; +} +if($CalcLT==1) +{ + print ""; +} +if($CalcLT==2) +{ + print ""; +} + print ""; print "\n"; print "\n"; @@ -160,24 +190,59 @@ for ($m = 1 ; $m < 13 ; $m++ ) $var=!$var; print ""; print ''; - - $x_coll = 0; - foreach($coll_listsell as $vatrate=>$val) + if($CalcLT==0) { - $x_coll+=$val['localtax2']; - } - $subtotalcoll = $subtotalcoll + $x_coll; - print ""; + $x_coll = 0; + foreach($coll_listsell as $vatrate=>$val) + { + $x_coll+=$val[$localTaxType==1?'localtax1':'localtax2']; + } + $subtotalcoll = $subtotalcoll + $x_coll; + print ""; - $x_paye = 0; - foreach($coll_listbuy as $vatrate=>$val) + $x_paye = 0; + foreach($coll_listbuy as $vatrate=>$val) + { + $x_paye+=$val[$localTaxType==1?'localtax1':'localtax2']; + } + $subtotalpaye = $subtotalpaye + $x_paye; + print ""; + } + elseif($CalcLT==1) { - $x_paye+=$val['localtax2']; + $x_paye = 0; + foreach($coll_listbuy as $vatrate=>$val) + { + $x_paye+=$val[$localTaxType==1?'localtax1':'localtax2']; + } + $subtotalpaye = $subtotalpaye + $x_paye; + print ""; } - $subtotalpaye = $subtotalpaye + $x_paye; - print ""; - - $diff = $x_coll - $x_paye; + elseif($CalcLT==2) + { + $x_coll = 0; + foreach($coll_listsell as $vatrate=>$val) + { + $x_coll+=$val[$localTaxType==1?'localtax1':'localtax2']; + } + $subtotalcoll = $subtotalcoll + $x_coll; + print ""; + + } + + if($CalcLT==0) + { + $diff= $x_coll - $x_paye; + } + elseif($CalcLT==1) + { + $diff= $x_paye; + } + elseif($CalcLT==2) + { + $diff= $x_coll; + } + $total = $total + $diff; $subtotal = $subtotal + $diff; @@ -186,12 +251,26 @@ for ($m = 1 ; $m < 13 ; $m++ ) print "\n"; $i++; - if ($i > 2) { + if ($i > 2) + { print ''; print ''; - print ''; - print ''; - print ''; + if($CalcLT==0) + { + print ''; + print ''; + print ''; + } + elseif($CalcLT==1) + { + print ''; + print ''; + } + elseif($CalcLT==2) + { + print ''; + print ''; + } print ''; $i = 0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0; @@ -214,6 +293,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."localtax as f"; $sql.= " WHERE f.entity = ".$conf->entity; $sql.= " AND f.datev >= '".$db->idate(dol_get_first_day($y,1,false))."'"; $sql.= " AND f.datev <= '".$db->idate(dol_get_last_day($y,12,false))."'"; +$sql.= " AND localtaxtype=".$localTaxType; $sql.= " GROUP BY dm ASC"; pt($db, $sql,$langs->trans("Year")." $y"); diff --git a/htdocs/compta/localtax/quadri_detail.php b/htdocs/compta/localtax/quadri_detail.php new file mode 100644 index 00000000000..a400d1b96a4 --- /dev/null +++ b/htdocs/compta/localtax/quadri_detail.php @@ -0,0 +1,669 @@ + + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2006-2007 Yannick Warnier + * Copyright (C) 2014 Rosana Romero + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/tva/quadri_detail.php + * \ingroup tax + * \brief Trimestrial page - detailed version + * TODO Deal with recurrent invoices as well + */ +global $mysoc; + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; + +$langs->load("bills"); +$langs->load("compta"); +$langs->load("companies"); +$langs->load("products"); + +$local=GETPOST('localTaxType', 'int'); +// Date range +$year=GETPOST("year"); +if (empty($year)) +{ + $year_current = strftime("%Y",dol_now()); + $year_start = $year_current; +} else { + $year_current = $year; + $year_start = $year; +} +$date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); +$date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]); +// Quarter +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ + $q=GETPOST("q"); + if (empty($q)) + { + if (isset($_REQUEST["month"])) { $date_start=dol_get_first_day($year_start,$_REQUEST["month"],false); $date_end=dol_get_last_day($year_start,$_REQUEST["month"],false); } + else + { + $month_current = strftime("%m",dol_now()); + if ($month_current >= 10) $q=4; + elseif ($month_current >= 7) $q=3; + elseif ($month_current >= 4) $q=2; + else $q=1; + } + } + if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); } + if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); } + if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); } + if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); } +} + +$min = GETPOST("min"); +if (empty($min)) $min = 0; + +// Define modetax (0 or 1) +// 0=normal, 1=option vat for services is on debit +$modetax = $conf->global->TAX_MODE; +if (isset($_REQUEST["modetax"])) $modetax=$_REQUEST["modetax"]; +if (empty($modetax)) $modetax=0; + +// Security check +$socid = GETPOST('socid','int'); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'tax', '', '', 'charges'); + + + +/* + * View + */ + +$morequerystring=''; +$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday'); +foreach($listofparams as $param) +{ + if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param); +} + +llxHeader('','','','',0,0,'','',$morequerystring); + +$form=new Form($db); + +$company_static=new Societe($db); +$invoice_customer=new Facture($db); +$invoice_supplier=new FactureFournisseur($db); +$product_static=new Product($db); +$payment_static=new Paiement($db); +$paymentfourn_static=new PaiementFourn($db); + +//print_fiche_titre($langs->trans("VAT"),""); + +//$fsearch.='
'; +$fsearch.=' '; +$fsearch.=' '; +//$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': '; +//$fsearch.=' '; + +$calc=MAIN_INFO_LOCALTAX_CALC.$local; +// Affiche en-tete du rapport +if ($conf->global->$calc==0 || $conf->global->$calc==1) // Calculate on invoice for goods and services +{ + $nom=$langs->trans($local==1?"LT1ReportByQuartersInDueDebtMode":"LT2ReportByQuartersInDueDebtMode"); + $calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT'.$local.'Rec"); + $calcmode.='
('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')'; + $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); + $prevyear=$year_start; $prevquarter=$q; + if ($prevquarter > 1) $prevquarter--; + else { $prevquarter=4; $prevyear--; } + $nextyear=$year_start; $nextquarter=$q; + if ($nextquarter < 4) $nextquarter++; + else { $nextquarter=1; $nextyear++; } + //$periodlink=($prevyear?"".img_previous()." ".img_next()."":""); + //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='
'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite'); + //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='
'.$langs->trans("WarningDepositsNotIncluded"); + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.='
'.$langs->trans("DepositsAreNotIncluded"); + else $description.='
'.$langs->trans("DepositsAreIncluded"); + $description.=$fsearch; + $builddate=time(); + //$exportlink=$langs->trans("NotYetAvailable"); + + $elementcust=$langs->trans("CustomersInvoices"); + $productcust=$langs->trans("ProductOrService"); + $amountcust=$langs->trans("AmountHT"); + $vatcust=$langs->trans("VATReceived"); + if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')'; + $elementsup=$langs->trans("SuppliersInvoices"); + $productsup=$langs->trans("ProductOrService"); + $amountsup=$langs->trans("AmountHT"); + $vatsup=$langs->trans("VATPaid"); + if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')'; +} +if ($conf->global->$calc==2) // Invoice for goods, payment for services +{ + $nom=$langs->trans($local==1?"LT1ReportByQuartersInInputOutputMode":"LT2ReportByQuartersInInputOutputMode"); + $calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT'.$local.'Rec"); + $calcmode.='
('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')'; + $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); + $prevyear=$year_start; $prevquarter=$q; + if ($prevquarter > 1) $prevquarter--; + else { $prevquarter=4; $prevyear--; } + $nextyear=$year_start; $nextquarter=$q; + if ($nextquarter < 4) $nextquarter++; + else { $nextquarter=1; $nextyear++; } + //$periodlink=($prevyear?"".img_previous()." ".img_next()."":""); + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.=' '.$langs->trans("DepositsAreNotIncluded"); + else $description.=' '.$langs->trans("DepositsAreIncluded"); + //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='
'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite'); + //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='
'.$langs->trans("WarningDepositsNotIncluded"); + $description.=$fsearch; + $builddate=time(); + //$exportlink=$langs->trans("NotYetAvailable"); + + $elementcust=$langs->trans("CustomersInvoices"); + $productcust=$langs->trans("ProductOrService"); + $amountcust=$langs->trans("AmountHT"); + $vatcust=$langs->trans("VATReceived"); + if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')'; + $elementsup=$langs->trans("SuppliersInvoices"); + $productsup=$langs->trans("ProductOrService"); + $amountsup=$langs->trans("AmountHT"); + $vatsup=$langs->trans("VATPaid"); + if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')'; +} +report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode); + + +if($local==1){ + $vatcust=$langs->transcountry("LocalTax1", $mysoc->country_code); + $vatsup=$langs->transcountry("LocalTax1", $mysoc->country_code); +}else{ + $vatcust=$langs->transcountry("LocalTax2", $mysoc->country_code); + $vatsup=$langs->transcountry("LocalTax2", $mysoc->country_code); +} + +// VAT Received and paid + + + +$y = $year_current; +$total = 0; +$i=0; + +// Load arrays of datas +$x_coll= local_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell', $local); +//$x_coll = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell'); +$x_paye = local_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy', $local); + + +echo '
".$langs->trans("Year")." $y".$langs->transcountry("LT2Customer",$mysoc->country_code)."".$langs->transcountry("LT2Supplier",$mysoc->country_code)."".$langs->transcountry($LTCustomer,$mysoc->country_code)."".$langs->transcountry($LTSupplier,$mysoc->country_code)."".$langs->transcountry($LTSupplier,$mysoc->country_code)."".$langs->transcountry($LTCustomer,$mysoc->country_code)."".$langs->trans("TotalToPay")." 
'.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").'".price($x_coll)."".price($x_coll)."".price($x_paye)."".price($x_paye)."".price($x_paye)."".price($x_coll)."
'.$langs->trans("SubTotal").':'.price($subtotalcoll).''.price($subtotalpaye).''.price($subtotal).''.price($subtotalcoll).''.price($subtotalpaye).''.price($subtotal).''.price($subtotalpaye).''.price($subtotal).''.price($subtotalcoll).''.price($subtotal).' 
'; + +if (! is_array($x_coll) || ! is_array($x_paye)) +{ + $langs->load("errors"); + if ($x_coll == -1) + print ''; + else if ($x_coll == -2) + print ''; + else + print ''; +} +else +{ + $x_both = array(); + //now, from these two arrays, get another array with one rate per line + foreach(array_keys($x_coll) as $my_coll_rate) + { + //foreach($x_coll[$my_coll_rate][localtax1_list]){ + $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht']; + $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat']; + $x_both[$my_coll_rate]['paye']['totalht'] = 0; + $x_both[$my_coll_rate]['paye']['vat'] = 0; + $x_both[$my_coll_rate]['coll']['links'] = ''; + $x_both[$my_coll_rate]['coll']['detail'] = array(); + foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) + { + $invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id]; + $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id]; + $invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id]; + $x_both[$my_coll_rate]['coll']['detail'][] = array( + 'id' =>$x_coll[$my_coll_rate]['facid'][$id], + 'descr' =>$x_coll[$my_coll_rate]['descr'][$id], + 'pid' =>$x_coll[$my_coll_rate]['pid'][$id], + 'pref' =>$x_coll[$my_coll_rate]['pref'][$id], + 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id], + 'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id], + 'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id], + 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id], + 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id], + 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id], + 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id], + 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id], + 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], + 'localtax1'=> $x_coll[$my_coll_rate]['localtax1_list'][$id], + 'localtax2'=> $x_coll[$my_coll_rate]['localtax2_list'][$id], + 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], + 'link' =>$invoice_customer->getNomUrl(1,'',12)); + } + } + // tva paid + foreach(array_keys($x_paye) as $my_paye_rate){ + $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht']; + $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat']; + if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){ + $x_both[$my_paye_rate]['coll']['totalht'] = 0; + $x_both[$my_paye_rate]['coll']['vat'] = 0; + } + $x_both[$my_paye_rate]['paye']['links'] = ''; + $x_both[$my_paye_rate]['paye']['detail'] = array(); + + foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy) + { + $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; + $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; + $invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id]; + $x_both[$my_paye_rate]['paye']['detail'][] = array( + 'id' =>$x_paye[$my_paye_rate]['facid'][$id], + 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], + 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], + 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], + 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], + 'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id], + 'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id], + 'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), + 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), + 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], + 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id], + 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], + 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), + 'localtax1'=> $x_paye[$my_paye_rate]['localtax1_list'][$id], + 'localtax2'=> $x_paye[$my_paye_rate]['localtax2_list'][$id], + 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], + 'link' =>$invoice_supplier->getNomUrl(1,'',12)); + } + } + //now we have an array (x_both) indexed by rates for coll and paye + + + //print table headers for this quadri - incomes first + + $x_coll_sum = 0; + $x_coll_ht = 0; + $x_paye_sum = 0; + $x_paye_ht = 0; + + $span=3; + if ($modetax == 0) $span+=2; + + //print ''; + + if($conf->global->$calc ==0 || $conf->global->$calc == 2){ + // Customers invoices + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''; + + + $LT=0; + $sameLT=false; + foreach(array_keys($x_coll) as $rate) + { + $subtot_coll_total_ht = 0; + $subtot_coll_vat = 0; + + if (is_array($x_both[$rate]['coll']['detail'])) + { + // VAT Rate + $var=true; + + if($rate!=0){ + print ""; + //print ''; + /**/ + print ''; + print ''."\n"; + } + foreach($x_both[$rate]['coll']['detail'] as $index => $fields) + { + if(($local==1 && $fields['localtax1']!=0) || ($local==2 && $fields['localtax2']!=0)){ + // Define type + $type=($fields['dtype']?$fields['dtype']:$fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (! empty($fields['ddate_start'])) $type=1; + if (! empty($fields['ddate_end'])) $type=1; + + $var=!$var; + print ''; + + // Ref + print ''; + + // Description + print ''; + + // Total HT + if ($modetax == 0) + { + print ''; + } + + // Payment + $ratiopaymentinvoice=1; + if ($modetax == 0) + { + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + print ''; + } + + // Total collected + print ''; + + // Localtax + print ''; + print ''; + + $subtot_coll_total_ht += $temp_ht; + $subtot_coll_vat += $temp_vat; + $x_coll_sum += $temp_vat; + } + } + } + if($rate!=0){ + // Total customers for this vat rate + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''; + } + } + + if (count($x_coll) == 0) // Show a total ine if nothing shown + { + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''; + } + + // Blank line + print ''; + print '
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("Error").'
'..')
'.$elementcust.''.$productcust.''.$amountcust.''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'.$langs->trans("BI").''.$vatcust.'
'.$langs->trans("Rate").': '.vatrate($rate).'%'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$fields['link'].''; + if ($fields['pid']) + { + $product_static->id=$fields['pid']; + $product_static->ref=$fields['pref']; + $product_static->type=$fields['ptype']; + print $product_static->getNomUrl(1); + if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + } + else + { + if ($type) $text = img_object($langs->trans('Service'),'service'); + else $text = img_object($langs->trans('Product'),'product'); + if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) + { + if ($reg[1]=='DEPOSIT') $fields['descr']=$langs->transnoentitiesnoconv('Deposit'); + elseif ($reg[1]=='CREDIT_NOTE') $fields['descr']=$langs->transnoentitiesnoconv('CreditNote'); + else $fields['descr']=$langs->transnoentitiesnoconv($reg[1]); + } + print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + + // Show range + print_date_range($fields['ddate_start'],$fields['ddate_end']); + } + print ''; + print price($fields['totalht']); + if (price2num($fields['ftotal_ttc'])) + { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print ''; + //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) + { + $payment_static->id=$fields['payment_id']; + print $payment_static->getNomUrl(2); + } + if ($type == 0) + { + print $langs->trans("NotUsedForGoods"); + } + else { + print $fields['payment_amount']; + if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + } + print ''; + $temp_ht=$fields['totalht']; + if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + print price(price2num($temp_ht,'MT')); + print ''; + $temp_vat= $local==1?$fields['localtax1']:$fields['localtax2']; + print price(price2num($temp_vat,'MT')); + //print price($fields['vat']); + print '
'.$langs->trans("Total").':  '.price(price2num($subtot_coll_total_ht,'MT')).''.price(price2num($subtot_coll_vat,'MT')).'
 '.$langs->trans("Total").':  '.price(price2num(0,'MT')).''.price(price2num(0,'MT')).'
 
'; + $diff=$x_coll_sum; + } + + if($conf->global->$calc ==0 || $conf->global->$calc == 1){ + echo ''; + //print table headers for this quadri - expenses now + //imprime les en-tete de tables pour ce quadri - maintenant les d�penses + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''."\n"; + + foreach(array_keys($x_paye) as $rate) + { + $subtot_paye_total_ht = 0; + $subtot_paye_vat = 0; + + if(is_array($x_both[$rate]['paye']['detail'])) + { + $var=true; + if($rate!=0){ + print ""; + print ''; + print ''."\n"; + } + foreach($x_both[$rate]['paye']['detail'] as $index=>$fields) + { + if(($local==1 && $fields['localtax1']!=0) || ($local==2 && $fields['localtax2']!=0)){ + // Define type + $type=($fields['dtype']?$fields['dtype']:$fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (! empty($fields['ddate_start'])) $type=1; + if (! empty($fields['ddate_end'])) $type=1; + + $var=!$var; + print ''; + + // Ref + print ''; + + // Description + print ''; + + // Total HT + if ($modetax == 0) + { + print ''; + } + + // Payment + $ratiopaymentinvoice=1; + if ($modetax == 0) + { + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + print ''; + } + + // VAT paid + print ''; + + // Localtax + print ''; + print ''; + + $subtot_paye_total_ht += $temp_ht; + $subtot_paye_vat += $temp_vat; + $x_paye_sum += $temp_vat; + } + } + } + if($rate!=0){ + // Total suppliers for this vat rate + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''; + } + } + + if (count($x_paye) == 0) // Show a total ine if nothing shown + { + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''; + } + + print '
'.$elementsup.''.$productsup.''.$amountsup.''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'.$langs->trans("BI").''.$vatsup.'
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$fields['link'].''; + if ($fields['pid']) + { + $product_static->id=$fields['pid']; + $product_static->ref=$fields['pref']; + $product_static->type=$fields['ptype']; + print $product_static->getNomUrl(1); + if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + } + else + { + if ($type) $text = img_object($langs->trans('Service'),'service'); + else $text = img_object($langs->trans('Product'),'product'); + print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + + // Show range + print_date_range($fields['ddate_start'],$fields['ddate_end']); + } + print ''; + print price($fields['totalht']); + if (price2num($fields['ftotal_ttc'])) + { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print ''; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) + { + $paymentfourn_static->id=$fields['payment_id']; + print $paymentfourn_static->getNomUrl(2); + } + if ($type == 0) + { + print $langs->trans("NotUsedForGoods"); + } + else + { + print $fields['payment_amount']; + if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + } + print ''; + $temp_ht=$fields['totalht']; + if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + print price(price2num($temp_ht,'MT')); + print ''; + $temp_vat= $local==1?$fields['localtax1']:$fields['localtax2']; + print price(price2num($temp_vat,'MT')); + //print price($fields['vat']); + print '
 '.$langs->trans("Total").':  '.price(price2num($subtot_paye_total_ht,'MT')).''.price(price2num($subtot_paye_vat,'MT')).'
 '.$langs->trans("Total").':  '.price(price2num(0,'MT')).''.price(price2num(0,'MT')).'
'; + $diff=$x_paye_sum; + } + + if($conf->global->$calc ==0){$diff=$x_coll_sum - $x_paye_sum;} + echo ''; + // Total to pay + print '

'; + print '
'; + //$diff = $local==1?$x_coll_sum:$x_paye_sum; + print ''; + print ''; + print '\n"; + print "\n"; + + echo '
'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').''.price(price2num($diff,'MT'))."
'; + + $i++; +} + +$db->close(); + +llxFooter(); +?> diff --git a/htdocs/compta/localtax/reglement.php b/htdocs/compta/localtax/reglement.php index 00199dba36f..6d8c1bc7a9c 100644 --- a/htdocs/compta/localtax/reglement.php +++ b/htdocs/compta/localtax/reglement.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2014 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ $langs->load("compta"); $socid = isset($_GET["socid"])?$_GET["socid"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', '', '', 'charges'); +$ltt=$_REQUEST["localTaxType"]; /* * View @@ -40,11 +41,11 @@ llxHeader(); $localtax_static = new Localtax($db); -print_fiche_titre($langs->transcountry("LT2Payments",$mysoc->country_code)); +print_fiche_titre($langs->transcountry($ltt==2?"LT2Payments":"LT1Payments",$mysoc->country_code)); $sql = "SELECT rowid, amount, label, f.datev as dm"; $sql.= " FROM ".MAIN_DB_PREFIX."localtax as f "; -$sql.= " WHERE f.entity = ".$conf->entity; +$sql.= " WHERE f.entity = ".$conf->entity." AND localtaxtype=".$ltt; $sql.= " ORDER BY dm DESC"; $result = $db->query($sql); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index ca3aea39a47..c97050371aa 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1,7 +1,7 @@ * Copyright (C) 2010 Regis Houssin - * Copyright (C) 2012-2013 Juanjo Menent + * Copyright (C) 2012-2014 Juanjo Menent * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify @@ -834,15 +834,24 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu global $mysoc; //Local Taxes - if($mysoc->country_code=='ES' && (isset($mysoc->localtax2_assuj) && $mysoc->localtax2_assuj=="1")) + //Local Taxes 1 + if($mysoc->useLocalTax(1) && (isset($mysoc->localtax1_assuj) && $mysoc->localtax1_assuj=="1")) { - if (empty($leftmenu) || preg_match('/^tax_vat/i',$leftmenu)) $newmenu->add("/compta/localtax/index.php?leftmenu=tax_vat&mainmenu=accountancy",$langs->transcountry("LT2",$mysoc->country_code),1,$user->rights->tax->charges->lire); - if (empty($leftmenu) || preg_match('/^tax_vat/i',$leftmenu)) $newmenu->add("/compta/localtax/fiche.php?leftmenu=tax_vat&action=create",$langs->trans("NewPayment"),2,$user->rights->tax->charges->creer); - if (empty($leftmenu) || preg_match('/^tax_vat/i',$leftmenu)) $newmenu->add("/compta/localtax/reglement.php?leftmenu=tax_vat",$langs->trans("Payments"),2,$user->rights->tax->charges->lire); - if (empty($leftmenu) || preg_match('/^tax_vat/i',$leftmenu)) $newmenu->add("/compta/localtax/clients.php?leftmenu=tax_vat", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire); - //if (empty($leftmenu) || preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_vat", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire); + $newmenu->add("/compta/localtax/index.php?leftmenu=tax_vat&mainmenu=accountancy&localTaxType=1",$langs->transcountry("LT1",$mysoc->country_code),1,$user->rights->tax->charges->lire); + if (empty($leftmenu) || preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/fiche.php?leftmenu=tax_vat&action=create&localTaxType=1",$langs->trans("NewPayment"),2,$user->rights->tax->charges->creer); + if (empty($leftmenu) || preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/reglement.php?leftmenu=tax_vat&localTaxType=1",$langs->trans("Payments"),2,$user->rights->tax->charges->lire); + if (empty($leftmenu) || preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/clients.php?leftmenu=tax_vat&localTaxType=1", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire); + if (empty($leftmenu) || preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_vat&localTaxType=1", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire); + } + //Local Taxes 2 + if($mysoc->useLocalTax(2) && (isset($mysoc->localtax2_assuj) && $mysoc->localtax2_assuj=="1")) + { + $newmenu->add("/compta/localtax/index.php?leftmenu=tax_vat&mainmenu=accountancy&localTaxType=2",$langs->transcountry("LT2",$mysoc->country_code),1,$user->rights->tax->charges->lire); + if (empty($leftmenu) || preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/fiche.php?leftmenu=tax_vat&action=create&localTaxType=2",$langs->trans("NewPayment"),2,$user->rights->tax->charges->creer); + if (empty($leftmenu) || preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/reglement.php?leftmenu=tax_vat&localTaxType=2",$langs->trans("Payments"),2,$user->rights->tax->charges->lire); + if (empty($leftmenu) || preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/clients.php?leftmenu=tax_vat&localTaxType=2", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire); + if (empty($leftmenu) || preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_vat&localTaxType=2", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire); } - } } }