diff --git a/htdocs/compta/tva/clients.php b/htdocs/compta/tva/clients.php index 07798f5f63e..0d0c0167dbf 100644 --- a/htdocs/compta/tva/clients.php +++ b/htdocs/compta/tva/clients.php @@ -67,7 +67,7 @@ llxHeader(); $company_static=new Societe($db); -print_fiche_titre($langs->trans("VAT"),""); +//print_fiche_titre($langs->trans("VAT"),""); $fsearch='
'; $fsearch.=' '; @@ -140,7 +140,7 @@ print "".$langs->trans("SalesTurnover")." ".$langs->trans("H print "".$vatcust.""; print "\n"; -$coll_list = vat_received_by_customer($db,$year_current,$modetax); +$coll_list = vat_by_thirdparty($db,$year_current,$modetax,'sell'); if (is_array($coll_list)) { $var=true; @@ -207,7 +207,7 @@ print "\n"; $company_static=new Societe($db); -$coll_list = vat_payed_by_supplier($db,$year_current,$modetax); +$coll_list = vat_by_thirdparty($db,$year_current,$modetax,'buy'); if (is_array($coll_list)) { $var=true; diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 7a32a0f8313..2f2ba536b91 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -33,7 +33,9 @@ require_once(DOL_DOCUMENT_ROOT."/lib/tax.lib.php"); require_once(DOL_DOCUMENT_ROOT."/tva.class.php"); require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); +require_once(DOL_DOCUMENT_ROOT."/paiement.class.php"); require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.facture.class.php"); +require_once(DOL_DOCUMENT_ROOT."/fourn/facture/paiementfourn.class.php"); $langs->load("bills"); $langs->load("compta"); @@ -41,14 +43,15 @@ $langs->load("companies"); $langs->load("products"); $year=$_GET["year"]; -if ($year == 0 ) +if (empty($year)) { - $year_current = strftime("%Y",time()); - $year_start = $year_current; + $year_current = strftime("%Y",time()); + $year_start = $year_current; } else { - $year_current = $year; - $year_start = $year; + $year_current = $year; + $year_start = $year; } +$q=(! empty($_GET["q"]))?$_GET["q"]:1; // Define modetax (0 or 1) $modetax = $conf->global->TAX_MODE; @@ -66,16 +69,24 @@ $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"),""); +//print_fiche_titre($langs->trans("VAT"),""); // Affiche en-tête du rapport if ($modetax==1) // Caluclate on invoice for goods and services { $nom=$langs->trans("VATReportByQuartersInDueDebtMode"); - $nom.='
('.$langs->trans("SeeVATReportInInputOutputMode",'','').')'; - $period=$year_start; - $periodlink=($year_start?"".img_previous()." ".img_next()."":""); + $nom.='
('.$langs->trans("SeeVATReportInInputOutputMode",'','').')'; + $period=$year_start.' - '.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(12,0,0,(($q-1)*3)+1,1,$year_start)).' - '.strftime("%b %Y",dolibarr_mktime(12,0,0,($q*3),1,$year_start)).")"; + $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()."":""); $description=$langs->trans("RulesVATDue"); if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='
'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite'); $description.=$fsearch; @@ -96,9 +107,15 @@ if ($modetax==1) // Caluclate on invoice for goods and services if ($modetax==0) // Invoice for goods, payment for services { $nom=$langs->trans("VATReportByQuartersInInputOutputMode"); - $nom.='
('.$langs->trans("SeeVATReportInDueDebtMode",'','').')'; - $period=$year_start; - $periodlink=($year_start?"".img_previous()." ".img_next()."":""); + $nom.='
('.$langs->trans("SeeVATReportInDueDebtMode",'','').')'; + $period=$year_start.' - '.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(12,0,0,(($q-1)*3)+1,1,$year_start)).' - '.strftime("%b %Y",dolibarr_mktime(12,0,0,($q*3),1,$year_start)).")"; + $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()."":""); $description=$langs->trans("RulesVATIn"); if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='
'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite'); $description.=$fsearch; @@ -124,186 +141,188 @@ report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportl echo ''; $y = $year_current; -for ($q = 1 ; $q <= 4 ; $q++ ) + +$total = 0; $subtotal = 0; +$i=0; +$subtot_coll_total = 0; +$subtot_coll_vat = 0; +$subtot_paye_total = 0; +$subtot_paye_vat = 0; + +$x_coll = vat_by_quarter($db, $y, $q, $modetax, 'sell'); +$x_paye = vat_by_quarter($db, $y, $q, $modetax, 'buy'); + +if (! is_array($x_coll) || ! is_array($x_paye)) { - $total = 0; $subtotal = 0; - $i=0; - $subtot_coll_total = 0; - $subtot_coll_vat = 0; - $subtot_paye_total = 0; - $subtot_paye_vat = 0; - - $x_coll = vat_by_quarter($db, $y, $q, $modetax, 'sell'); - $x_paye = vat_by_quarter($db, $y, $q, $modetax, 'buy'); - - if (! is_array($x_coll) || ! is_array($x_paye)) - { - print ''; - //print ''; - break; - } - - $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) - { - $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]; - $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], - 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], - 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], - 'link' =>$invoice_customer->getNomUrl(1)); - //$x_both[$my_coll_rate]['coll']['links'] .= '..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).' '; - } - } - // tva payed - 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(); + print ''; + //print ''; + break; +} - 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]; - $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'=>$x_paye[$my_paye_rate]['ftotal_ttc'][$id], - 'dtotal_ttc'=>$x_paye[$my_paye_rate]['dtotal_ttc'][$id], - 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], - 'totalht' =>$x_paye[$my_paye_rate]['totalht_list'][$id], - 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], - 'link' =>$invoice_supplier->getNomUrl(1)); - //$x_both[$my_paye_rate]['paye']['links'] .= '..'.substr($x_paye[$my_paye_rate]['facnum'][$id],-2).' '; - } - } - //now we have an array (x_both) indexed by rates for coll and paye - - //print table headers for this quadri - incomes first - //imprime les en-tete de tables pour ce quadri - d'abord les revenus - - $x_coll_sum = 0; - $x_coll_ht = 0; - $x_paye_sum = 0; - $x_paye_ht = 0; - - $span=3; - if ($modetax == 0) $span+=2; - - print ''; - - print ''; - print ''; - print ''; - if ($modetax == 0) +$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) +{ + $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) { - print ''; - print ''; + $invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id]; + $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$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], + 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], + 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], + 'link' =>$invoice_customer->getNomUrl(1)); + //$x_both[$my_coll_rate]['coll']['links'] .= '..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).' '; } - print ''; - print ''; - print ''; - $var=true; - foreach(array_keys($x_coll) as $rate) +} +// tva payed +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) { - if (is_array($x_both[$rate]['coll']['detail'])) + $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; + $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$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'=>$x_paye[$my_paye_rate]['ftotal_ttc'][$id], + 'dtotal_ttc'=>$x_paye[$my_paye_rate]['dtotal_ttc'][$id], + 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], + 'totalht' =>$x_paye[$my_paye_rate]['totalht_list'][$id], + 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], + 'link' =>$invoice_supplier->getNomUrl(1)); + //$x_both[$my_paye_rate]['paye']['links'] .= '..'.substr($x_paye[$my_paye_rate]['facnum'][$id],-2).' '; + } +} +//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 ''; + +print ''; +print ''; +print ''; +if ($modetax == 0) +{ + print ''; + print ''; +} +print ''; +print ''; +print ''; +foreach(array_keys($x_coll) as $rate) +{ + if (is_array($x_both[$rate]['coll']['detail'])) + { + $var=true; + print ""; + print ''; + print ''."\n"; + foreach($x_both[$rate]['coll']['detail'] as $index => $fields) { - print ""; - print ''; - print ''."\n"; - foreach($x_both[$rate]['coll']['detail'] as $index => $fields) + $var=!$var; + print ''; + print ''; + print ''; - print ''; - print ''; - // Amount line - if ($modetax == 0) - { - print ''; - } - // Payment - $ratiopaymentinvoice=1; - if ($modetax == 0) - { - if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); - print ''; - } - print ''; - // VAT - print ''; - print ''; - - $subtot_coll_total += $temp_ht; - $subtot_coll_vat += $temp_vat; - $x_coll_sum += $temp_vat; + $product_static->id=$fields['pid']; + $product_static->ref=$fields['pref']; + $product_static->type=$fields['ptype']; + print $product_static->getNomUrl(1); + if ($fields['descr']) print ' - '; } + else + { + if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); + else $text = img_object($langs->trans('Product'),'product'); + print $text.' '; + } + print dolibarr_trunc($fields['descr'],24).''; + // Amount line + if ($modetax == 0) + { + print ''; + } + // Payment + $ratiopaymentinvoice=1; + if ($modetax == 0) + { + if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + print ''; + } + print ''; + // VAT + print ''; + print ''; + + $subtot_coll_total += $temp_ht; + $subtot_coll_vat += $temp_vat; + $x_coll_sum += $temp_vat; } } - print ''; print ''; print ''; @@ -315,95 +334,102 @@ for ($q = 1 ; $q <= 4 ; $q++ ) print ''; print ''; print ''; +} - - //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 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) +{ + if(is_array($x_both[$rate]['paye']['detail'])) { - print ''; - print ''; - } - print ''; - print ''; - print ''."\n"; - $var=true; - foreach(array_keys($x_paye) as $rate) - { - if(is_array($x_both[$rate]['paye']['detail'])) + $var=true; + print ""; + print ''; + print ''."\n"; + foreach($x_both[$rate]['paye']['detail'] as $index=>$fields) { - print ""; - print ''; - print ''."\n"; - foreach($x_both[$rate]['paye']['detail'] as $index=>$fields) + $var=!$var; + print ''; + print ''; + print ''; - print ''; - print ''; - // Amount line - if ($modetax == 0) - { - print ''; - } - // Payment - $ratiopaymentinvoice=1; - if ($modetax == 0) - { - if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); - print ''; - } - print ''; - // VAT - print ''; - print ''; - - $subtot_paye_total += $temp_ht; - $subtot_paye_vat += $temp_vat; - $x_paye_sum += $temp_vat; + $product_static->id=$fields['pid']; + $product_static->ref=$fields['pref']; + $product_static->type=$fields['ptype']; + print $product_static->getNomUrl(1); + if ($fields['descr']) print ' - '; } + else + { + if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); + else $text = img_object($langs->trans('Product'),'product'); + print $text.' '; + } + print dolibarr_trunc($fields['descr'],24).''; + // Amount line + if ($modetax == 0) + { + print ''; + } + // Payment + $ratiopaymentinvoice=1; + if ($modetax == 0) + { + if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + print ''; + } + print ''; + // VAT + print ''; + print ''; + + $subtot_paye_total += $temp_ht; + $subtot_paye_vat += $temp_vat; + $x_paye_sum += $temp_vat; } - } - + } + print ''; - print ''; + print ''; print ''; if ($modetax == 0) { @@ -413,23 +439,23 @@ for ($q = 1 ; $q <= 4 ; $q++ ) print ''; print ''; print ''; +} - print ''; - print ''; - print ''."\n"; +print ''; +print ''; +print ''."\n"; - $diff = $x_coll_sum - $x_paye_sum; - //$total = $total + $diff; - //$subtotal = $subtotal + $diff; - print ""; - print ''; - print '\n"; - print "\n"; +$diff = $x_coll_sum - $x_paye_sum; +//$total = $total + $diff; +//$subtotal = $subtotal + $diff; +print ""; +print ''; +print '\n"; +print "\n"; - print ''."\n"; +print ''."\n"; - $i++; -} +$i++; echo '
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'
'.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(12,0,0,(($q-1)*3)+1,1,$y)).' - '.strftime("%b %Y",dolibarr_mktime(12,0,0,($q*3),1,$y)).')
'.$elementcust.''.$productcust.''.$amountcust.''.$langs->trans("Payment").' (% of invoice)'.$langs->trans("AmountHTVATRealReceived").''.$vatcust.'
'..')
'.$elementcust.''.$productcust.''.$amountcust.''.$langs->trans("Payment").' (% of invoice)'.$langs->trans("AmountHTVATRealReceived").''.$vatcust.'
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$fields['link'].''; + if ($fields['pid']) { - $var=!$var; - print '
'.$fields['link'].''; - if ($fields['pid']) - { - $product_static->id=$fields['pid']; - $product_static->ref=$fields['pref']; - $product_static->fk_product_type=$fields['ptype']; - print $product_static->getNomUrl(1); - if ($fields['descr']) print ' - '; - } - else - { - if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); - else $text = img_object($langs->trans('Product'),'product'); - print $text.' '; - } - print dolibarr_trunc($fields['descr'],24).''; - print price($fields['totalht']); - if ($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['payment_amount']; - if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; - print ''; - $temp_ht=$fields['totalht']; - if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; - print price(price2num($temp_ht,'MT')); - print ''; - $temp_vat=$fields['vat']*$ratiopaymentinvoice; - print price(price2num($temp_vat,'MT')); - //print price($fields['vat']); - print '
'; + print price($fields['totalht']); + if ($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']) + { + $payment_static->rowid=$fields['payment_id']; + print $payment_static->getNomUrl(2); + } + print $fields['payment_amount']; + if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + print ''; + $temp_ht=$fields['totalht']; + if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + print price(price2num($temp_ht,'MT')); + print ''; + $temp_vat=$fields['vat']*$ratiopaymentinvoice; + print price(price2num($temp_vat,'MT')); + //print price($fields['vat']); + print '
'.$langs->trans("Total").':'.price(price2num($subtot_coll_total,'MT')).''.price(price2num($subtot_coll_vat,'MT')).'
'.$elementsup.''.$productsup.'
 
'.$elementsup.''.$productsup.''.$amountsup.''.$langs->trans("Payment").' (% of invoice)'.$langs->trans("AmountHTVATRealPayed").''.$vatsup.'
'.$amountsup.''.$langs->trans("Payment").' (% of invoice)'.$langs->trans("AmountHTVATRealPayed").''.$vatsup.'
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$fields['link'].''; + if ($fields['pid']) { - $var=!$var; - print '
'.$fields['link'].''; - if ($fields['pid']) - { - $product_static->id=$fields['pid']; - $product_static->ref=$fields['pref']; - $product_static->fk_product_type=$fields['ptype']; - print $product_static->getNomUrl(1); - if ($fields['descr']) print ' - '; - } - else - { - if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); - else $text = img_object($langs->trans('Product'),'product'); - print $text.' '; - } - print dolibarr_trunc($fields['descr'],24).''; - print price($fields['totalht']); - if ($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['payment_amount']; - if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; - print ''; - $temp_ht=$fields['totalht']; - if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; - print price(price2num($temp_ht,'MT')); - print ''; - $temp_vat=$fields['vat']*$ratiopaymentinvoice; - print price(price2num($temp_vat,'MT')); - //print price($fields['vat']); - print '
'; + print price($fields['totalht']); + if ($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->rowid=$fields['payment_id']; + print $paymentfourn_static->getNomUrl(2); + } + print $fields['payment_amount']; + if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + print ''; + $temp_ht=$fields['totalht']; + if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + print price(price2num($temp_ht,'MT')); + print ''; + $temp_vat=$fields['vat']*$ratiopaymentinvoice; + print price(price2num($temp_vat,'MT')); + //print price($fields['vat']); + print '
 '.$langs->trans("Total").':'.price(price2num($subtot_paye_total,'MT')).''.price(price2num($subtot_paye_vat,'MT')).'
'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").$q.'
'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").$q.'
'.price(price2num($diff,'MT'))."
'.price(price2num($diff,'MT'))."
 
 
'; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 68d1b7d4e8e..7734f4c92d1 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -404,7 +404,7 @@ class Facture extends CommonObject if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; - $result.=$lien.$this->ref.$lienfin; + if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; return $result; } diff --git a/htdocs/fourn/facture/paiementfourn.class.php b/htdocs/fourn/facture/paiementfourn.class.php index c05ba69f444..672f8e7ac32 100644 --- a/htdocs/fourn/facture/paiementfourn.class.php +++ b/htdocs/fourn/facture/paiementfourn.class.php @@ -16,17 +16,14 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ */ /** \file htdocs/fourn/facture/paiementfourn.class.php \ingroup fournisseur, facture - \brief Page de cr�ation de paiement factures fournisseurs - \remarks Cette classe est presque identique � paiement.class.php - \version $Revision$ + \brief Classe paiement fournisseur + \remarks Cette classe est presque identique a paiement.class.php + \version $Id$ */ require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php'); @@ -455,5 +452,27 @@ class PaiementFourn } return $langs->trans('Unknown'); } + + + /** + * \brief Renvoie nom clicable (avec eventuellement le picto) + * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul + * \param option Sur quoi pointe le lien + * \return string Chaine avec URL + */ + function getNomUrl($withpicto=0,$option='') + { + global $langs; + + $result=''; + + $lien = ''; + $lienfin=''; + + if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.$this->rowid.$lienfin; + return $result; + } } ?> diff --git a/htdocs/lib/tax.lib.php b/htdocs/lib/tax.lib.php index c794e169def..24fdc81836b 100644 --- a/htdocs/lib/tax.lib.php +++ b/htdocs/lib/tax.lib.php @@ -30,12 +30,30 @@ * \param db Database handle * \param y Year * \param modetax 0 or 1 (option vat on debit) + * \param direction 'sell' or 'buy' * \return array List of customers third parties with vat */ -function vat_received_by_customer($db, $y, $modetax) +function vat_by_thirdparty($db, $y, $modetax, $direction) { global $conf; + $list=array(); + + if ($direction == 'sell') + { + $invoicetable='facture'; + $invoicedettable='facturedet'; + $fk_facture='fk_facture'; + $total_tva='total_tva'; + } + if ($direction == 'buy') + { + $invoicetable='facture_fourn'; + $invoicedettable='facture_fourn_det'; + $fk_facture='fk_facture_fourn'; + $total_tva='tva'; + } + // Define sql request $sql=''; if ($modetax == 1) @@ -52,13 +70,13 @@ function vat_received_by_customer($db, $y, $modetax) if ($conf->global->MAIN_MODULE_COMPTABILITE) { $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,"; - $sql.= " sum(fd.total_ht) as amount, sum(fd.total_tva) as tva,"; + $sql.= " sum(fd.total_ht) as amount, sum(fd.".$total_tva.") as tva,"; $sql.= " s.tva_assuj as assuj, s.rowid as socid"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."societe as s"; + $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicedettable." as fd, ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE "; $sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely) $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; - $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture"; + $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture; $sql.= " GROUP BY s.rowid"; } } @@ -77,13 +95,13 @@ function vat_received_by_customer($db, $y, $modetax) { // Tva sur factures payés (should be on payment) /* $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,"; - $sql.= " sum(fd.total_ht) as amount, sum(fd.total_tva) as tva,"; + $sql.= " sum(fd.total_ht) as amount, sum(".$total_tva.") as tva,"; $sql.= " s.tva_assuj as assuj, s.rowid as socid"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."societe as s"; + $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicetable." as fd, ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE "; $sql.= " f.fk_statut in (2)"; // Payed (partially or completely) $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; - $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture"; + $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture; $sql.= " GROUP BY s.rowid"; */ } @@ -91,16 +109,15 @@ function vat_received_by_customer($db, $y, $modetax) if ($sql) { - dolibarr_syslog("Client::tva_coll sql=".$sql); + dolibarr_syslog("Client::vat_by_customer sql=".$sql); $resql = $db->query($sql); if ($resql) { - $list = array(); while($assoc = $db->fetch_array($resql)) { $list[] = $assoc; } - $db->free(); + $db->free($resql); return $list; } else @@ -116,99 +133,6 @@ function vat_received_by_customer($db, $y, $modetax) } -/** - * \brief Get payable VAT - * \param resource Database handle - * \param y Year - * \param modetax 0 or 1 (option vat on debit) - * \return array List of suppliers third parties with vat - */ -function vat_payed_by_supplier($db, $y, $modetax) -{ - global $conf; - - // Define sql request - $sql=''; - if ($modetax == 1) - { - // If vat payed on due invoices (non draft) - if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT) - { - // \todo a ce jour on se sait pas la compter car le montant tva d'un payment - // n'est pas stocké dans la table des payments. - // Seul le module compta expert peut résoudre ce problème. - // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le - // detail part tva et part ht). - } - if ($conf->global->MAIN_MODULE_COMPTABILITE) - { - $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,"; - $sql.= " sum(fd.total_ht) as amount, sum(fd.tva) as tva,"; - $sql.= " s.tva_assuj as assuj, s.rowid as socid"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."facture_fourn_det as fd, ".MAIN_DB_PREFIX."societe as s"; - $sql.= " WHERE "; - $sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely) - $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; - $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture_fourn"; - $sql.= " GROUP BY s.rowid"; - } - } - else - { - // Si on paye la tva sur les payments - - if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT) - { - // \todo a ce jour on se sait pas la compter car le montant tva d'un payment - // n'est pas stocké dans la table des payments. - // Seul le module compta expert peut résoudre ce problème. - // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le - // detail part tva et part ht). - } - if ($conf->global->MAIN_MODULE_COMPTABILITE) - { - // Tva sur factures payés -/* $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,"; - $sql.= " sum(fd.total_ht) as amount, sum(fd.tva) as tva,"; - $sql.= " s.tva_assuj as assuj, s.rowid as socid"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."facture_fourn_det as fd, ".MAIN_DB_PREFIX."societe as s"; - $sql.= " WHERE "; - //$sql.= " f.fk_statut in (2)"; // Payed (partially or completely) - $sql.= " f.paye in (1)"; // Payed (completely) - $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; - $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture_fourn"; - $sql.= " GROUP BY s.rowid"; -*/ - } - } - - if ($sql) - { - dolibarr_syslog("Client::tva_paye sql=".$sql); - $resql = $db->query($sql); - if ($resql) - { - $list = array(); - while($assoc = $db->fetch_array($resql)) - { - $list[] = $assoc; - } - return $list; - } - else - { - dolibarr_print_error($db); - return -2; - } - } - else - { - return -1; - } -} - - - /** * \brief Gets VAT to collect for the given month of the given year * The function gets the VAT in split results, as the VAT declaration asks @@ -232,14 +156,22 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) $invoicetable='facture'; $invoicedettable='facturedet'; $fk_facture='fk_facture'; + $fk_facture2='fk_facture'; + $fk_payment='fk_paiement'; $total_tva='total_tva'; + $paymenttable='paiement'; + $paymentfacturetable='paiement_facture'; } if ($direction == 'buy') { $invoicetable='facture_fourn'; $invoicedettable='facture_fourn_det'; $fk_facture='fk_facture_fourn'; + $fk_facture2='fk_facturefourn'; + $fk_payment='fk_paiementfourn'; $total_tva='tva'; + $paymenttable='paiementfourn'; + $paymentfacturetable='paiementfourn_facturefourn'; } // CAS DES BIENS @@ -405,17 +337,17 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux 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.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,"; $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; - $sql.= " pf.fk_paiement as payment_id, pf.amount as payment_amount"; + $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount"; $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; - $sql.= " ".MAIN_DB_PREFIX."paiement_facture as pf,"; - $sql.= " ".MAIN_DB_PREFIX."paiement as pa,"; + $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; + $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " WHERE "; $sql.= " f.fk_statut in (1,2)"; // Payed (partially or completely) $sql.= " AND f.rowid = d.".$fk_facture;; - $sql.= " AND pf.fk_facture = f.rowid"; - $sql.= " AND pa.rowid = pa.fk_paiement"; + $sql.= " AND pf.".$fk_facture2." = f.rowid"; + $sql.= " AND pa.rowid = pf.".$fk_payment; $sql.= " AND pa.datep >= '".$y."0101000000' AND pa.datep <= '".$y."1231235959'"; $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; $sql.= " AND d.product_type = 1"; // Limit to services diff --git a/htdocs/paiement.class.php b/htdocs/paiement.class.php index b9be8720e96..aa5d2d68235 100644 --- a/htdocs/paiement.class.php +++ b/htdocs/paiement.class.php @@ -410,7 +410,7 @@ class Paiement /** * \brief Renvoie nom clicable (avec eventuellement le picto) - * \param withpicto Inclut le picto dans le lien + * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul * \param option Sur quoi pointe le lien * \return string Chaine avec URL */ @@ -423,8 +423,9 @@ class Paiement $lien = ''; $lienfin=''; - if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin.' '); - $result.=$lien.$this->rowid.$lienfin; + if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.$this->rowid.$lienfin; return $result; }