diff --git a/htdocs/compta/localtax/class/localtax.class.php b/htdocs/compta/localtax/class/localtax.class.php new file mode 100644 index 00000000000..9bb1f1c559a --- /dev/null +++ b/htdocs/compta/localtax/class/localtax.class.php @@ -0,0 +1,592 @@ + + * + * 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 2 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/localtax/class/localtax.class.php + * \ingroup tax + * \author Laurent Destailleur + */ + +require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); + + +/** + \class Localtax + \brief Put here description of your class +*/ +class localtax extends CommonObject +{ + var $id; + var $ref; + var $tms; + var $datep; + var $datev; + var $amount; + var $label; + var $note; + var $fk_bank; + var $fk_user_creat; + var $fk_user_modif; + + /** + * Constructor + * + * @param DoliDB $DB Database handler + */ + function localtax($DB) + { + $this->db = $DB; + return 1; + } + + + /** + * Create in database + * + * @param User $user User that create + * @return int <0 if KO, >0 if OK + */ + function create($user) + { + global $conf, $langs; + + // Clean parameters + + $this->amount=trim($this->amount); + $this->label=trim($this->label); + $this->note=trim($this->note); + $this->fk_bank=trim($this->fk_bank); + $this->fk_user_creat=trim($this->fk_user_creat); + $this->fk_user_modif=trim($this->fk_user_modif); + + // Insert request + $sql = "INSERT INTO ".MAIN_DB_PREFIX."localtax("; + $sql.= "tms,"; + $sql.= "datep,"; + $sql.= "datev,"; + $sql.= "amount,"; + $sql.= "label,"; + $sql.= "note,"; + $sql.= "fk_bank,"; + $sql.= "fk_user_creat,"; + $sql.= "fk_user_modif"; + $sql.= ") VALUES ("; + $sql.= " ".$this->db->idate($this->tms).","; + $sql.= " ".$this->db->idate($this->datep).","; + $sql.= " ".$this->db->idate($this->datev).","; + $sql.= " '".$this->amount."',"; + $sql.= " '".$this->label."',"; + $sql.= " '".$this->note."',"; + $sql.= " ".($this->fk_bank <= 0 ? "NULL" : "'".$this->fk_bank."'").","; + $sql.= " '".$this->fk_user_creat."',"; + $sql.= " '".$this->fk_user_modif."'"; + $sql.= ")"; + + dol_syslog("localtax::create sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."localtax"); + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + return $this->id; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog("localtax::create ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * Update database + * @param user User that modify + * @param notrigger 0=no, 1=yes (no update trigger) + * @return int <0 if KO, >0 if OK + */ + function update($user=0, $notrigger=0) + { + global $conf, $langs; + + // Clean parameters + $this->amount=trim($this->amount); + $this->label=trim($this->label); + $this->note=trim($this->note); + $this->fk_bank=trim($this->fk_bank); + $this->fk_user_creat=trim($this->fk_user_creat); + $this->fk_user_modif=trim($this->fk_user_modif); + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."localtax SET"; + $sql.= " tms=".$this->db->idate($this->tms).","; + $sql.= " datep=".$this->db->idate($this->datep).","; + $sql.= " datev=".$this->db->idate($this->datev).","; + $sql.= " amount='".$this->amount."',"; + $sql.= " label='".$this->db->escape($this->label)."',"; + $sql.= " note='".$this->db->escape($this->note)."',"; + $sql.= " fk_bank='".$this->fk_bank."',"; + $sql.= " fk_user_creat='".$this->fk_user_creat."',"; + $sql.= " fk_user_modif='".$this->fk_user_modif."'"; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog("localtax::update sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog("localtax::update ".$this->error, LOG_ERR); + return -1; + } + + if (! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + return 1; + } + + + /** + * Load object in memory from database + * @param id id object + * @param user User that load + * @return int <0 if KO, >0 if OK + */ + function fetch($id, $user=0) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.tms,"; + $sql.= " t.datep,"; + $sql.= " t.datev,"; + $sql.= " t.amount,"; + $sql.= " t.label,"; + $sql.= " t.note,"; + $sql.= " t.fk_bank,"; + $sql.= " t.fk_user_creat,"; + $sql.= " t.fk_user_modif,"; + $sql.= " b.fk_account,"; + $sql.= " b.fk_type,"; + $sql.= " b.rappro"; + $sql.= " FROM ".MAIN_DB_PREFIX."localtax as t"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid"; + $sql.= " WHERE t.rowid = ".$id; + + dol_syslog("localtax::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->tms = $this->db->jdate($obj->tms); + $this->datep = $this->db->jdate($obj->datep); + $this->datev = $this->db->jdate($obj->datev); + $this->amount = $obj->amount; + $this->label = $obj->label; + $this->note = $obj->note; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + $this->fk_account = $obj->fk_account; + $this->fk_type = $obj->fk_type; + $this->rappro = $obj->rappro; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog("localtax::fetch ".$this->error, LOG_ERR); + return -1; + } + } + + + /** + * Delete object in database + * @param user User that delete + * @return int <0 if KO, >0 if OK + */ + function delete($user) + { + global $conf, $langs; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."localtax"; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog("localtax::delete sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog("localtax::delete ".$this->error, LOG_ERR); + return -1; + } + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + return 1; + } + + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + function initAsSpecimen() + { + $this->id=0; + + $this->tms=''; + $this->datep=''; + $this->datev=''; + $this->amount=''; + $this->label=''; + $this->note=''; + $this->fk_bank=''; + $this->fk_user_creat=''; + $this->fk_user_modif=''; + } + + + /** + * Hum la fonction s'appelle 'Solde' elle doit a mon avis calcluer le solde de localtax, non ? + * + */ + function solde($year = 0) + { + + $reglee = $this->localtax_sum_reglee($year); + + $payee = $this->localtax_sum_payee($year); + $collectee = $this->localtax_sum_collectee($year); + + $solde = $reglee - ($collectee - $payee); + + return $solde; + } + + /** + * Total de la localtax des factures emises par la societe. + * + */ + + function localtax_sum_collectee($year = 0) + { + + $sql = "SELECT sum(f.localtax) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1"; + + if ($year) + { + $sql .= " AND f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; + } + + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + return $obj->amount; + } + else + { + return 0; + } + + $this->db->free($result); + + } + else + { + print $this->db->error(); + return -1; + } + } + + /** + * localtax payed + * + */ + + function localtax_sum_payee($year = 0) + { + + $sql = "SELECT sum(f.total_localtax) as total_localtax"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + + if ($year) + { + $sql .= " WHERE f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; + } + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + return $obj->total_localtax; + } + else + { + return 0; + } + + $this->db->free(); + + } + else + { + print $this->db->error(); + return -1; + } + } + + + /** + * localtax payed + * Total de la localtax payed + * + */ + + function localtax_sum_reglee($year = 0) + { + + $sql = "SELECT sum(f.amount) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."localtax as f"; + + if ($year) + { + $sql .= " WHERE f.datev >= '$year-01-01' AND f.datev <= '$year-12-31' "; + } + + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + return $obj->amount; + } + else + { + return 0; + } + + $this->db->free(); + + } + else + { + print $this->db->error(); + return -1; + } + } + + + /** + * Add a payment of localtax + * @param user Object user that insert + * @return int <0 if KO, rowid in localtax table if OK + */ + function addPayment($user) + { + global $conf,$langs; + + $this->db->begin(); + + // Check parameters + $this->amount=price2num($this->amount); + if (! $this->label) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); + return -3; + } + if ($this->amount <= 0) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")); + return -4; + } + if ($conf->banque->enabled && (empty($this->accountid) || $this->accountid <= 0)) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Account")); + return -5; + } + if ($conf->banque->enabled && (empty($this->paymenttype) || $this->paymenttype <= 0)) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")); + return -5; + } + + // Insertion dans table des paiement localtax + $sql = "INSERT INTO ".MAIN_DB_PREFIX."localtax (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.= "'".$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)."'"; + $sql.=", '".$user->id."', NULL"; + $sql.= ")"; + + dol_syslog("localtax::addPayment sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."localtax"); // TODO devrait s'appeler paiementlocaltax + if ($this->id > 0) + { + $ok=1; + if ($conf->banque->enabled) + { + // Insertion dans llx_bank + require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); + + $acc = new Account($this->db); + $result=$acc->fetch($this->accountid); + if ($result <= 0) dol_print_error($db); + + $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount), '', '', $user); + + // Mise a jour fk_bank dans llx_localtax. On connait ainsi la ligne de localtax qui a g�n�r� l'�criture bancaire + if ($bank_line_id > 0) + { + $this->update_fk_bank($bank_line_id); + } + else + { + $this->error=$acc->error; + $ok=0; + } + + // Mise a jour liens + $result=$acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT.'/compta/localtax/fiche.php?id=', "(VATPayment)", "payment_vat"); + if ($result < 0) + { + $this->error=$acc->error; + $ok=0; + } + } + + if ($ok) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -3; + } + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -2; + } + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } + + /** + * Update the link betwen localtax payment and the line into llx_bank + * @param id_bank Id compte bancaire + * @return int <0 if KO, >0 if OK + */ + function update_fk_bank($id_bank) + { + $sql = 'UPDATE llx_localtax set fk_bank = '.$id_bank; + $sql.= ' WHERE rowid = '.$this->id; + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } + + + /** + * brief Returns clickable name + * @param withpicto 0=Link, 1=Picto into link, 2=Picto + * @param option Sur quoi pointe le lien + * @return string Chaine avec URL + */ + function getNomUrl($withpicto=0,$option='') + { + global $langs; + + $result=''; + + $lien = ''; + $lienfin=''; + + $picto='payment'; + $label=$langs->trans("ShowVatPayment").': '.$this->ref; + + if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; + return $result; + } + +} +?> \ No newline at end of file diff --git a/htdocs/compta/localtax/clients.php b/htdocs/compta/localtax/clients.php new file mode 100644 index 00000000000..6f2bbae3029 --- /dev/null +++ b/htdocs/compta/localtax/clients.php @@ -0,0 +1,299 @@ + + * + * 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 2 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/localtax/clients.php + * \ingroup tax + * \brief Third parties localtax report + */ + +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"); + +$langs->load("bills"); +$langs->load("compta"); +$langs->load("companies"); +$langs->load("products"); + +// 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"]; + +// Security check +$socid = GETPOST("socid"); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'tax', '', '', 'charges'); + +/* + * View + */ + +$html=new Form($db); +$company_static=new Societe($db); + +$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); + +$fsearch.='
'; +$fsearch.=' '; +$fsearch.=' '; +$fsearch.=' '.$langs->trans("SalesTurnover").' '.$langs->trans("Minimum").': '; +$fsearch.=' '; + +// Affiche en-tete du rapport +if ($modetax==1) // Calculate on invoice for goods and services +{ + $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->pays_code); + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + $description=$langs->trans("RulesVATDue"); + if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='
'.$langs->trans("WarningDepositsNotIncluded"); + $description.=$fsearch; + $description.='
('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')'; + $builddate=time(); + + $elementcust=$langs->trans("CustomersInvoices"); + $productcust=$langs->trans("Description"); + $amountcust=$langs->trans("AmountHT"); + $elementsup=$langs->trans("SuppliersInvoices"); + $productsup=$langs->trans("Description"); + $amountsup=$langs->trans("AmountHT"); +} +if ($modetax==0) // Invoice for goods, payment for services +{ + $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->pays_code); + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + $description=$langs->trans("RulesVATIn"); + if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='
'.$langs->trans("WarningDepositsNotIncluded"); + $description.=$fsearch; + $description.='
('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')'; + $builddate=time(); + + $elementcust=$langs->trans("CustomersInvoices"); + $productcust=$langs->trans("Description"); + $amountcust=$langs->trans("AmountHT"); + $elementsup=$langs->trans("SuppliersInvoices"); + $productsup=$langs->trans("Description"); + $amountsup=$langs->trans("AmountHT"); +} +report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); + +$vatcust=$langs->transcountry("LT2",$mysoc->pays_code); +$vatsup=$langs->transcountry("LT2",$mysoc->pays_code); + +// IRPF that the customer has retained me + +print ""; +print ""; +print '"; +print '"; +print ""; +print ""; +print ""; +print "\n"; + +$coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell'); +if (is_array($coll_list)) +{ + $var=true; + $total = 0; $totalamount = 0; + $i = 1; + foreach($coll_list as $coll) + { + if(($min == 0 or ($min > 0 && $coll->amount > $min)) && $coll->localtax2>0) + { + $var=!$var; + $intra = str_replace($find,$replace,$coll->tva_intra); + if(empty($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 + $coll->localtax2; + print "\n"; + $i++; + } + } + $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 ''; +} + +// IRPF I retained my supplier + +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'); +if (is_array($coll_list)) +{ + $var=true; + $total = 0; $totalamount = 0; + $i = 1; + foreach($coll_list as $coll) + { + if(($min == 0 or ($min > 0 && $coll->amount > $min)) && $coll->localtax2>0) + { + $var=!$var; + $intra = str_replace($find,$replace,$coll->tva_intra); + if(empty($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 + $coll->localtax2; + print "\n"; + $i++; + } + } + $x_paye_sum = $total; + + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Num")."'.$langs->trans("Customer")."".$langs->transcountry("ProfId1",$mysoc->pays_code)."".$langs->trans("TotalHT")."".$vatcust."
".$i."'.$company_static->getNomUrl(1).'".$intra."".price($coll->amount)."".price($coll->localtax2)."
'.$langs->trans("Total").':'.price($totalamount).''.price($total).'
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("Error").'
'.$langs->trans("Num")."'.$langs->trans("Supplier")."".$langs->transcountry("ProfId1",$mysoc->pays_code)."".$langs->trans("TotalHT")."".$vatsup."
".$i."'.$company_static->getNomUrl(1).'".$intra."".price($coll->amount)."".price($coll->localtax2)."
'.$langs->trans("Total").':'.price($totalamount).''.price($total).'
'; + + // 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 ''; +} + +print '
'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').''.price(price2num($diff,'MT'))."
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("Error").'
'; + + +$db->close(); + +llxFooter(); +?> diff --git a/htdocs/compta/localtax/fiche.php b/htdocs/compta/localtax/fiche.php new file mode 100644 index 00000000000..b27fe6f63b2 --- /dev/null +++ b/htdocs/compta/localtax/fiche.php @@ -0,0 +1,266 @@ + + * + * 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 2 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/localtax/fiche.php + * \ingroup tax + * \brief Page of IRPF payments + */ + +require('../../main.inc.php'); +require_once(DOL_DOCUMENT_ROOT."/compta/localtax/class/localtax.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); + +$langs->load("compta"); +$langs->load("banks"); +$langs->load("bills"); + +$id=$_REQUEST["id"]; + +$mesg = ''; + +// Security check +$socid = isset($_GET["socid"])?$_GET["socid"]:''; +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'tax', '', '', 'charges'); + + +/* + * Actions + */ + +//add payment of localtax +if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) +{ + $localtax = new localtax($db); + + $db->begin(); + + $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]); + $datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]); + + $localtax->accountid=$_POST["accountid"]; + $localtax->paymenttype=$_POST["paiementtype"]; + $localtax->datev=$datev; + $localtax->datep=$datep; + $localtax->amount=$_POST["amount"]; + $localtax->label=$_POST["label"]; + + $ret=$localtax->addPayment($user); + if ($ret > 0) + { + $db->commit(); + Header("Location: reglement.php"); + exit; + } + else + { + $db->rollback(); + $mesg='
'.$localtax->error.'
'; + $_GET["action"]="create"; + } +} + +//delete payment of localtax +if ($_GET["action"] == 'delete') +{ + $localtax = new localtax($db); + $result=$localtax->fetch($_GET['id']); + + if ($localtax->rappro == 0) + { + $db->begin(); + + $ret=$localtax->delete($user); + if ($ret > 0) + { + if ($localtax->fk_bank) + { + $accountline=new AccountLine($db); + $result=$accountline->fetch($localtax->fk_bank); + $result=$accountline->delete($user); + } + + if ($result > 0) + { + $db->commit(); + header("Location: ".DOL_URL_ROOT.'/compta/localtax/reglement.php'); + exit; + } + else + { + $localtax->error=$accountline->error; + $db->rollback(); + $mesg='
'.$localtax->error.'
'; + } + } + else + { + $db->rollback(); + $mesg='
'.$localtax->error.'
'; + } + } + else + { + $mesg='
Error try do delete a line linked to a conciliated bank transaction
'; + } +} + + +/* +* View +*/ + +llxHeader(); + +$html = new Form($db); + +if ($id) +{ + $vatpayment = new localtax($db); + $result = $vatpayment->fetch($id); + if ($result <= 0) + { + dol_print_error($db); + exit; + } +} + + +if ($_GET["action"] == 'create') +{ + print "
\n"; + print ''; + print ''; + + print_fiche_titre($langs->transcountry("newLT2Payment",$mysoc->pays_code)); + + if ($mesg) print $mesg; + + print ''; + + print ""; + print ''; + + print ''; + + // Label + print ''; + + // Amount + print ''; + + if ($conf->banque->enabled) + { + print ''; + + print '\n"; + print ""; + } + print '
'.$langs->trans("DatePayment").''; + print $html->select_date($datep,"datep",'','','','add'); + print '
'.$langs->trans("DateValue").''; + print $html->select_date($datev,"datev",'','','','add'); + print '
'.$langs->trans("Label").'transcountry("LT2Payment",$mysoc->pays_code)).'">
'.$langs->trans("Amount").'
'.$langs->trans("Account").''; + $html->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant + print '
'.$langs->trans("PaymentMode").''; + $html->select_types_paiements($_POST["paiementtype"], "paiementtype"); + print "
'; + + print "
"; + + print '
  '; + print '
'; + + print '
'; +} + + +/* ************************************************************************** */ +/* */ +/* Barre d'action */ +/* */ +/* ************************************************************************** */ + +if ($id) +{ + if ($mesg) print $mesg; + + $h = 0; + $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/fiche.php?id='.$vatpayment->id; + $head[$h][1] = $langs->trans('Card'); + $head[$h][2] = 'card'; + $h++; + + dol_fiche_head($head, 'card', $langs->trans("VATPayment"), 0, 'payment'); + + + print ''; + + print ""; + print ''; + + print ""; + print ''; + + print ''; + + print ''; + + if ($conf->banque->enabled) + { + if ($vatpayment->fk_account > 0) + { + $bankline=new AccountLine($db); + $bankline->fetch($vatpayment->fk_bank); + + print ''; + print ''; + print ''; + print ''; + } + } + + print '
'.$langs->trans("Ref").''; + print $vatpayment->ref; + print '
'.$langs->trans("DatePayment").''; + print dol_print_date($vatpayment->datep,'day'); + print '
'.$langs->trans("DateValue").''; + print dol_print_date($vatpayment->datev,'day'); + print '
'.$langs->trans("Amount").''.price($vatpayment->amount).'
'.$langs->trans('BankTransactionLine').''; + print $bankline->getNomUrl(1,0,'showall'); + print '
'; + + print ''; + + /* + * Boutons d'actions + */ + print "
\n"; + if ($vatpayment->rappro == 0) + print ''.$langs->trans("Delete").''; + else + print ''.$langs->trans("Delete").''; + print "
"; +} + + +$db->close(); + +llxFooter(); + +?> diff --git a/htdocs/compta/localtax/index.php b/htdocs/compta/localtax/index.php new file mode 100644 index 00000000000..8f2239ebc59 --- /dev/null +++ b/htdocs/compta/localtax/index.php @@ -0,0 +1,219 @@ + + * + * 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 2 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/localtax/index.php + * \ingroup tax + * \brief Index page of IRPF reports + */ +require('../../main.inc.php'); +require_once(DOL_DOCUMENT_ROOT."/core/lib/tax.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/tva/class/tva.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); + +$langs->load("other"); + +$year=$_GET["year"]; +if ($year == 0 ) +{ + $year_current = strftime("%Y",time()); + $year_start = $year_current; +} else { + $year_current = $year; + $year_start = $year; +} + +// Security check +$socid = isset($_GET["socid"])?$_GET["socid"]:''; +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'tax', '', '', 'charges'); + +// Define modetax (0 or 1) +// 0=normal, 1=option vat for services is on debit +$modetax = $conf->global->TAX_MODE; +if (isset($_GET["modetax"])) $modetax=$_GET["modetax"]; + +function pt ($db, $sql, $date) +{ + global $conf, $bc,$langs; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + $total = 0; + print ''; + print ''; + print ''; + print ''; + print ''."\n"; + print "\n"; + $var=True; + while ($i < $num) + { + $obj = $db->fetch_object($result); + $var=!$var; + print ''; + print '\n"; + $total = $total + $obj->mm; + + print '\n"; + print "\n"; + + $i++; + } + print '"; + + print "
'.$date.''.$langs->trans("Amount").' 
'.$obj->dm."'.price($obj->mm)." 
'.$langs->trans("Total")." :".price($total)." 
"; + $db->free($result); + } + else { + dolibar_print_error($db); + } +} + + +/* + * View + */ + +llxHeader(); + +$tva = new Tva($db); + + +$textprevyear="".img_previous().""; +$textnextyear=" ".img_next().""; + +print_fiche_titre($langs->transcountry("LT2",$mysoc->pays_code),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear"); + +print $langs->trans("VATReportBuildWithOptionDefinedInModule").'
'; +print '('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')
'; +print '
'; + +print ''; +print ''; + +print '
'; +print_titre($langs->transcountry("LT2Summary",$mysoc->pays_code)); + +print ' '; +print_titre($langs->transcountry("LT2Paid",$mysoc->pays_code)); +print '
'; + +print ""; +print ""; +print ""; +print ""; +print ""; +print ""; +print "\n"; +print "\n"; + +$y = $year_current ; + +$var=True; +$total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0; +$i=0; +for ($m = 1 ; $m < 13 ; $m++ ) +{ + $coll_listsell = vat_by_date($db, $y, 0, 0, 0, $modetax, 'sell', $m); + $coll_listbuy = vat_by_date($db, $y, 0, 0, 0, $modetax, 'buy', $m); + + if (! is_array($coll_listbuy) && $coll_listbuy == -1) + { + $langs->load("errors"); + print ''; + break; + } + if (! is_array($coll_listbuy) && $coll_listbuy == -2) + { + print ''; + break; + } + + $var=!$var; + print ""; + print ''; + + $x_coll = 0; + foreach($coll_listsell as $vatrate=>$val) + { + $x_coll+=$val['localtax2']; + } + $subtotalcoll = $subtotalcoll + $x_coll; + print ""; + + $x_paye = 0; + foreach($coll_listbuy as $vatrate=>$val) + { + $x_paye+=$val['localtax2']; + } + $subtotalpaye = $subtotalpaye + $x_paye; + print ""; + + $diff = $x_coll - $x_paye; + $total = $total + $diff; + $subtotal = $subtotal + $diff; + + print "\n"; + print "\n"; + print "\n"; + + $i++; + if ($i > 2) { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $i = 0; + $subtotalcoll=0; $subtotalpaye=0; $subtotal=0; + } +} +print ''; +print "\n"; +print ''; + +print '
".$langs->trans("Year")." $y".$langs->transcountry("LT2Customer",$mysoc->pays_code)."".$langs->transcountry("LT2Supplier",$mysoc->pays_code)."".$langs->trans("TotalToPay")." 
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").'".price($x_coll)."".price($x_paye)."".price($diff)." 
'.$langs->trans("SubTotal").':'.price($subtotalcoll).''.price($subtotalpaye).''.price($subtotalpaye).' 
'.$langs->trans("TotalToPay").':'.price($total).' 
'; + +print '
 '; + +/* + * Payed + */ + +$sql = "SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm"; +$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.= " GROUP BY dm ASC"; + +pt($db, $sql,$langs->trans("Year")." $y"); + +print "
"; + +print ''; +print ''; + +$db->close(); + +llxFooter(); +?> diff --git a/htdocs/compta/localtax/reglement.php b/htdocs/compta/localtax/reglement.php new file mode 100644 index 00000000000..bcfc27194e0 --- /dev/null +++ b/htdocs/compta/localtax/reglement.php @@ -0,0 +1,97 @@ + + * + * 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 2 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/localtax/reglement.php + * \ingroup tax + * \brief List of IRPF payments + */ + +require('../../main.inc.php'); +require_once(DOL_DOCUMENT_ROOT."/compta/localtax/class/localtax.class.php"); + +$langs->load("compta"); +$langs->load("compta"); + +// Security check +$socid = isset($_GET["socid"])?$_GET["socid"]:''; +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'tax', '', '', 'charges'); + +/* + * View + */ + +llxHeader(); + +$localtax_static = new localtax($db); + +print_fiche_titre($langs->transcountry("LT2Payments",$mysoc->pays_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.= " ORDER BY dm DESC"; + +$result = $db->query($sql); +if ($result) +{ + $num = $db->num_rows($result); + $i = 0; + $total = 0 ; + + print ''; + print ''; + print ''; + print ""; + print ''; + print ""; + print "\n"; + $var=1; + while ($i < $num) + { + $obj = $db->fetch_object($result); + $var=!$var; + print ""; + + $localtax_static->id=$obj->rowid; + $localtax_static->ref=$obj->rowid; + print "\n"; + print "\n"; + print '\n"; + $total = $total + $obj->amount; + + print ""; + print "\n"; + + $i++; + } + print ''; + print ""; + + print "
'.$langs->trans("Ref").'".$langs->trans("Label")."'.$langs->trans("DatePayment").'".$langs->trans("PayedByThisPayment")."
".$localtax_static->getNomUrl(1)."".dol_trunc($obj->label,40)."'.dol_print_date($db->jdate($obj->dm),'day')."".price($obj->amount)."
'.$langs->trans("Total").'".price($total)."
"; + $db->free($result); +} +else +{ + dol_print_error($db); +} + +$db->close(); + +llxFooter(); +?> diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index d205b155185..3f6e6cb34ac 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -49,6 +49,8 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction $invoicedettable='facturedet'; $fk_facture='fk_facture'; $total_tva='total_tva'; + $total_localtax1='total_localtax1'; + $total_localtax2='total_localtax2'; } if ($direction == 'buy') { @@ -56,6 +58,8 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction $invoicedettable='facture_fourn_det'; $fk_facture='fk_facture_fourn'; $total_tva='tva'; + $total_localtax1='total_localtax1'; + $total_localtax2='total_localtax2'; } // Define sql request @@ -74,8 +78,10 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction } if ($conf->global->MAIN_MODULE_COMPTABILITE) { - $sql = "SELECT s.rowid as socid, s.nom as nom, s.tva_intra as tva_intra, s.tva_assuj as assuj,"; - $sql.= " sum(fd.total_ht) as amount, sum(fd.".$total_tva.") as tva"; + $sql = "SELECT s.rowid as socid, s.nom as nom, s.siren as tva_intra, s.tva_assuj as assuj,"; + $sql.= " sum(fd.total_ht) as amount, sum(fd.".$total_tva.") as tva,"; + $sql.= " sum(fd.".$total_localtax1.") as localtax1,"; + $sql.= " sum(fd.".$total_localtax2.") as localtax2"; $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as fd,"; $sql.= " ".MAIN_DB_PREFIX."societe as s"; @@ -195,6 +201,8 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $fk_facture2='fk_facture'; $fk_payment='fk_paiement'; $total_tva='total_tva'; + $total_localtax1='total_localtax1'; + $total_localtax2='total_localtax2'; $paymenttable='paiement'; $paymentfacturetable='paiement_facture'; } @@ -206,6 +214,8 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $fk_facture2='fk_facturefourn'; $fk_payment='fk_paiementfourn'; $total_tva='tva'; + $total_localtax1='total_localtax1'; + $total_localtax2='total_localtax2'; $paymenttable='paiementfourn'; $paymentfacturetable='paiementfourn_facturefourn'; } @@ -229,6 +239,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, { // Count on delivery date (use invoice date as delivery is unknown) $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql.= " d.date_start as date_start, d.date_end as date_end,"; $sql.= " f.facnumber as facnum, f.type, f.total_ttc as ftotal_ttc,"; $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; @@ -275,6 +286,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, { // Count on delivery date (use invoice date as delivery is unknown) $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql.= " d.date_start as date_start, d.date_end as date_end,"; $sql.= " f.facnumber as facnum, f.type, f.total_ttc as ftotal_ttc,"; $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; @@ -331,12 +343,16 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, { if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0; if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0; + if (! isset($list[$assoc['rate']]['locatax1'])) $list[$assoc['rate']]['localtax1']=0; + if (! isset($list[$assoc['rate']]['locatax2'])) $list[$assoc['rate']]['localtax2']=0; if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid { $oldrowid=$assoc['rowid']; $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; $list[$assoc['rate']]['vat'] += $assoc['total_vat']; + $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; + $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; } $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; @@ -351,6 +367,8 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; + $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; + $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; $list[$assoc['rate']]['pid'][] = $assoc['pid']; $list[$assoc['rate']]['pref'][] = $assoc['pref']; @@ -390,6 +408,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, { // Count on invoice date $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql.= " d.date_start as date_start, d.date_end as date_end,"; $sql.= " f.facnumber as facnum, f.type, f.total_ttc as ftotal_ttc,"; $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; @@ -437,6 +456,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, { // Count on payments date $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql.= " d.date_start as date_start, d.date_end as date_end,"; $sql.= " f.facnumber as facnum, f.type, f.total_ttc as ftotal_ttc,"; $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; @@ -491,12 +511,16 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, { if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0; if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0; + if (! isset($list[$assoc['rate']]['locatax1'])) $list[$assoc['rate']]['localtax1']=0; + if (! isset($list[$assoc['rate']]['locatax2'])) $list[$assoc['rate']]['localtax2']=0; if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid { $oldrowid=$assoc['rowid']; $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; $list[$assoc['rate']]['vat'] += $assoc['total_vat']; + $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; + $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; } $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; @@ -511,6 +535,8 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; + $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; + $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; $list[$assoc['rate']]['pid'][] = $assoc['pid']; $list[$assoc['rate']]['pref'][] = $assoc['pref']; diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 9cf00b15144..fef135ddf43 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -941,7 +941,20 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after) if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/tva/reglement.php?leftmenu=tax_vat",$langs->trans("Payments"),2,$user->rights->tax->charges->lire); if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/tva/clients.php?leftmenu=tax_vat", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire); if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/tva/quadri_detail.php?leftmenu=tax_vat", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire); + global $mysoc; + + //Local Taxes + if($mysoc->pays_code=='ES' && $mysoc->localtax2_assuj=="1") + { + if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/index.php?leftmenu=tax_vat&mainmenu=accountancy",$langs->transcountry("LT2",$mysoc->pays_code),1,$user->rights->tax->charges->lire); + if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/fiche.php?leftmenu=tax_vat&action=create",$langs->trans("NewPayment"),2,$user->rights->tax->charges->creer); + if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/reglement.php?leftmenu=tax_vat",$langs->trans("Payments"),2,$user->rights->tax->charges->lire); + if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/clients.php?leftmenu=tax_vat", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire); + //if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_vat", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire); + } + } + } // Compta simple diff --git a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql index db1a3928437..ad8aebf52a9 100755 --- a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql +++ b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql @@ -69,3 +69,17 @@ DROP TABLE IF EXISTS llx_pos_tmp; ALTER TABLE llx_deplacement ADD COLUMN fk_user_modif integer AFTER fk_user_author; +CREATE TABLE IF NOT EXISTS `llx_localtax` ( + `rowid` int(11) NOT NULL AUTO_INCREMENT, + `tms` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `datep` date DEFAULT NULL, + `datev` date DEFAULT NULL, + `amount` double NOT NULL DEFAULT '0', + `label` varchar(255) DEFAULT NULL, + `entity` int(11) NOT NULL DEFAULT '1', + `note` text, + `fk_bank` int(11) DEFAULT NULL, + `fk_user_creat` int(11) DEFAULT NULL, + `fk_user_modif` int(11) DEFAULT NULL, + PRIMARY KEY (`rowid`) +) ENGINE=InnoDB; diff --git a/htdocs/install/mysql/tables/llx_localtax.sql b/htdocs/install/mysql/tables/llx_localtax.sql new file mode 100644 index 00000000000..460c3c29c63 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_localtax.sql @@ -0,0 +1,42 @@ +-- =================================================================== +-- Copyright (C) 2002-2003 Rodolphe Quiedeville +-- Copyright (C) 2005-2009 Regis Houssin +-- Copyright (C) 2011 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 +-- the Free Software Foundation; either version 2 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 . +-- +-- =================================================================== + +create table llx_localtax +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + datep date, -- date of payment + datev date, -- date of value + amount real NOT NULL DEFAULT 0, + label varchar(255), + entity integer DEFAULT 1 NOT NULL, + note text, + fk_bank integer, + fk_user_creat integer, + fk_user_modif integer +)ENGINE=innodb; + +-- +-- List of codes for the field entity +-- +-- 1 : first company vat +-- 2 : second company vat +-- 3 : etc... +-- \ No newline at end of file diff --git a/htdocs/langs/ca_ES/main.lang b/htdocs/langs/ca_ES/main.lang index a7b91bf1f81..c7e728552cf 100644 --- a/htdocs/langs/ca_ES/main.lang +++ b/htdocs/langs/ca_ES/main.lang @@ -296,6 +296,8 @@ IncludedVAT=IVA inclòs HT=Sense IVA TTC=IVA inclòs VAT=IVA +LT1ES=RE +LT2ES=IRPF VATRate=Taxa IVA Average=Mitja Sum=Suma diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index 0e720a94b5d..6fb68b6bd24 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -37,7 +37,11 @@ VATToPay=VAT sells VATReceived=VAT received VATToCollect=VAT purchases VATSummary=VAT Balance +LT2SummaryES=IRPF Balance VATPaid=VAT paid +LT2PaidES=IRPF Paid +LT2CustomerES=IRPF sales +LT2SupplierES=IRPF purchases VATCollected=VAT collected ToPay=To pay ToGet=To get back @@ -63,6 +67,9 @@ ListOfCustomerPayments=List of customer payments ListOfSupplierPayments=List of supplier payments DatePayment=Payment date NewVATPayment=New VAT payment +newLT2PaymentES=New IRPF payment +LT2PaymentES=IRPF Payment +LT2PaymentsES=IRPF Payments VATPayment=VAT Payment VATPayments=VAT Payments SocialContributionsPayments=Social contributions payments @@ -104,6 +111,7 @@ RulesResultDue=- Amounts shown are with all taxes included
- It includes outs RulesResultInOut=- Amounts shown are with all taxes included
- It includes the real payments made on invoices, expenses and VAT.
- It is based on the payment dates of the invoices, expenses anf VAT.
RulesCADue=- It includes the client's due invoices (except deposit invoices) whether they are paid or not.
- It is based on the validation date of these invoices.
RulesCAIn=- It includes all the effective payments of invoices received from clients.
- It is based on the payment date of these invoices
+LT2ReportByCustomersInInputOutputModeES=Report by third party IRPF VATReportByCustomersInInputOutputMode=Report by the customer VAT collected and paid (VAT receipt) VATReportByCustomersInDueDebtMode=Report by the customer VAT collected and paid (VAT rate) VATReportByQuartersInInputOutputMode=Report by rate of the VAT collected and paid (VAT receipt) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 6684d5ed698..4ae7c7e8fad 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -298,6 +298,8 @@ IncludedVAT=Included tax HT=Net of tax TTC=Inc. tax VAT=Sales tax +LT1ES=RE +LT2ES=IRPF VATRate=Tax Rate Average=Average Sum=Sum diff --git a/htdocs/langs/es_ES/compta.lang b/htdocs/langs/es_ES/compta.lang index 8d7575fb961..64c104a878a 100644 --- a/htdocs/langs/es_ES/compta.lang +++ b/htdocs/langs/es_ES/compta.lang @@ -37,7 +37,11 @@ VATToPay=IVA ventas VATReceived=IVA repercutido VATToCollect=IVA compras VATSummary=Balance de IVA +LT2SummaryES=Balance de IRPF VATPaid=IVA Pagado +LT2PaidES=IRPF Pagado +LT2CustomerES=IRPF ventas +LT2SupplierES=IRPF compras VATCollected=IVA recuperado ToPay=A pagar ToGetBack=A recuperar @@ -63,6 +67,9 @@ ListOfCustomerPayments=Listado de pagos de clientes ListOfSupplierPayments=Listado de pagos a proveedores DatePayment=Fecha de pago NewVATPayment=Nuevo pago de IVA +newLT2PaymentES=Nuevo pago de IRPF +LT2PaymentES=Pago IRPF +LT2PaymentsES=Pagos IRPF VATPayment=Pago IVA VATPayments=Pagos IVA SocialContributionsPayments=Pagos cargas sociales @@ -104,6 +111,7 @@ RulesResultDue=- Los importes mostrados son importes totales
- Incluye las fa RulesResultInOut=- Los importes mostrados son importes totales
- Incluye los pagos realizados para las facturas, cargas e IVA.
- Se basa en la fecha de pago de las mismas.
RulesCADue=- Incluye las facturas a clientes (que no sean de anticipo), estén pagadas o no.
- Se base en la fecha de validación de las mismas.
RulesCAIn=- Incluye los pagos efectuados de las facturas a clientes.
- Se basa en la fecha de pago de las mismas
+LT2ReportByCustomersInInputOutputModeES=Informe por tercero del IRPF VATReportByCustomersInInputOutputMode=Informe por cliente del IVA repercutido y pagado (IVA pagado) VATReportByCustomersInDueDebtMode=Informe por cliente del IVA repercutido y pagado (IVA debido) VATReportByQuartersInInputOutputMode=Informe por tasa del IVA repercutido y pagado (IVA pagado) diff --git a/htdocs/langs/es_ES/main.lang b/htdocs/langs/es_ES/main.lang index 362aa346f85..04de2801b71 100644 --- a/htdocs/langs/es_ES/main.lang +++ b/htdocs/langs/es_ES/main.lang @@ -296,6 +296,8 @@ IncludedVAT=IVA incluido HT=Sin IVA TTC=IVA incluido VAT=IVA +LT1ES=RE +LT2ES=IRPF VATRate=Tasa IVA Average=Media Sum=Suma diff --git a/htdocs/langs/fr_FR/compta.lang b/htdocs/langs/fr_FR/compta.lang index 1bd9a474680..f4d2a469fb7 100644 --- a/htdocs/langs/fr_FR/compta.lang +++ b/htdocs/langs/fr_FR/compta.lang @@ -37,8 +37,12 @@ VATToPay=TVA ventes VATReceived=TVA collectée VATToCollect=TVA achats VATSummary=Balance de TVA +LT2SummaryES=Balance de IRPF VATPaid=TVA payée +LT2PaidES=IRPF Payée VATCollected=TVA récupérée +LT2CustomerES=IRPF ventes +LT2SupplierES=IRPF achats ToPay=A payer ToGetBack=A récupérer TaxAndDividendsArea=Espace taxes, charges sociales et dividendes @@ -65,6 +69,9 @@ DatePayment=Date de règlement NewVATPayment=Nouveau règlement de TVA VATPayment=Règlement TVA VATPayments=Règlements TVA +LT2PaymentES=Règlement IRPF +LT2PaymentsES=Règlements IRPF +newLT2PaymentES=Nouveau règlement de IRPF SocialContributionsPayments=Règlements charges sociales ShowVatPayment=Affiche paiement TVA TotalToPay=Total à payer @@ -104,6 +111,7 @@ RulesResultDue=- Les montants affichés sont les montants taxe incluse
- Il i RulesResultInOut=- Les montants affichés sont les montants taxe incluse
- Il inclut les règlements effectivement réalisés pour les factures, les charges et la TVA.
- Il se base sur la date de règlement de ces factures, charges et TVA.
RulesCADue=- Il inclut les factures clients dues (hors facture accompte), qu'elles soient payées ou non.
- Il se base sur la date de validation de ces factures.
RulesCAIn=- Il inclut les règlements effectivement reçus des factures clients.
- Il se base sur la date de règlement de ces factures
+LT2ReportByCustomersInInputOutputModeES=Rapport par client des IRPF VATReportByCustomersInInputOutputMode=Rapport par client des TVA collectées et payées (TVA sur encaissement) VATReportByCustomersInDueDebtMode=Rapport par client des TVA collectées et payées (TVA sur débit) VATReportByQuartersInInputOutputMode=Rapport par taux des TVA collectées et payées (TVA sur encaissement) diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 2fd6ce72242..d5a42c3a6e0 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -298,6 +298,8 @@ IncludedVAT=Dont TVA HT=HT TTC=TTC VAT=TVA +LT1ES=RE +LT2ES=IRPF VATRate=Taux TVA Average=Moyenne Sum=Somme