From a4815bf44c5e5d1eeac54691f02d9ebd148286cc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 8 Mar 2009 23:09:45 +0000 Subject: [PATCH] Prepare select of type of line --- htdocs/compta/facture.php | 78 +++++++++++++++++-------- htdocs/compta/tva/quadri_detail.php | 90 +++++++++++++++++++---------- htdocs/fourn/facture/fiche.php | 10 ++-- htdocs/lib/functions.lib.php | 2 +- htdocs/lib/tax.lib.php | 49 ++++++++++------ 5 files changed, 150 insertions(+), 79 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a69f2a6231b..fc24e7f29b0 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2636,7 +2636,7 @@ else /* - * Lignes de factures + * Lines of invoice */ $sql = 'SELECT l.fk_product, l.product_type, l.description, l.qty, l.rowid, l.tva_taux,'; $sql.= ' l.fk_remise_except,'; @@ -2644,6 +2644,7 @@ else $sql.= ' l.total_ht, l.total_tva, l.total_ttc,'; $sql.= ' '.$db->pdate('l.date_start').' as date_start,'; $sql.= ' '.$db->pdate('l.date_end').' as date_end,'; + $sql.= ' l.product_type,'; $sql.= ' p.ref, p.fk_product_type, p.label as product,'; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l'; @@ -2657,11 +2658,12 @@ else $num_lignes = $db->num_rows($resql); $i = 0; $total = 0; + $product_static=new Product($db); + print ''; if ($num_lignes) { - print ''; print ''; print ''; @@ -2671,7 +2673,6 @@ else print ''; print ''; print "\n"; - } $var=true; while ($i < $num_lignes) @@ -2679,6 +2680,13 @@ else $objp = $db->fetch_object($resql); $var=!$var; + // Show product and description + $type=$objp->product_type?$objp->product_type:$objp->fk_product_type; + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (! empty($objp->date_start)) $type=1; + if (! empty($objp->date_end)) $type=1; + // Ligne en mode visu if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { @@ -2688,20 +2696,21 @@ else print ''; } @@ -2737,9 +2746,11 @@ else } else { - if ($objp->fk_product_type==1) $text = img_object($langs->trans('Service'),'service'); + if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); print $text.' '.nl2br($objp->description); + + // Show range print_date_range($objp->date_start,$objp->date_end); } print "\n"; @@ -2824,17 +2835,27 @@ else print ''; print ''; + + // VAT print ''; + + // Unit price print ''; + + print ''; + print ''; + print ''; print '' . "\n"; @@ -2910,7 +2939,7 @@ else print ''; print "\n"; - // Ajout produit produits/services personalisés + // Add free products/services form print ''; print ''; print ''; @@ -2918,7 +2947,9 @@ else $var=true; print ''; print ''; print ''; print ''; @@ -2951,7 +2981,7 @@ else } print ''; - // Ajout de produits/services prédéfinis + // Add predefined services/products form if ($conf->produit->enabled) { print ''; diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index d2b05c777d8..56d21decc73 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -193,10 +193,11 @@ else '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], 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], 'link' =>$invoice_customer->getNomUrl(1,'',12)); - //$x_both[$my_coll_rate]['coll']['links'] .= '..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).' '; } } // tva payed @@ -223,13 +224,14 @@ else '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], + '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], - 'totalht' =>$x_paye[$my_paye_rate]['totalht_list'][$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]), 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], 'link' =>$invoice_supplier->getNomUrl(1,'',12)); - //$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 @@ -275,13 +277,20 @@ else foreach($x_both[$rate]['coll']['detail'] as $index => $fields) { + // 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 + // Description print ''; // Total HT @@ -305,7 +316,7 @@ else { print ''; } // Total collected print ''; // VAT print ''; @@ -398,13 +412,20 @@ else print ''."\n"; foreach($x_both[$rate]['paye']['detail'] as $index=>$fields) { + // 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 + // Description print ''; + print ''; // Total HT if ($modetax == 0) { print ''; } // VAT payed print ''; // VAT print ''; diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index b56a7b081b8..6d7d9ca4fe3 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -522,8 +522,7 @@ else print ''; /* - * Lignes - * + * Lines of invoice */ print '
'; $var=true; @@ -540,6 +539,7 @@ else for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) { $var=!$var; + // Affichage simple de la ligne print ''; print ''; @@ -697,7 +697,7 @@ else print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('TotalHT').' 
'; print ''; // ancre pour retourner sur la ligne - // Affiche ligne produit - $text = ''; - if ($objp->fk_product_type==1) $text.= img_object($langs->trans('ShowService'),'service'); - else $text.= img_object($langs->trans('ShowProduct'),'product'); - $text.= ' '.$objp->ref.''; + // Show product and description + $product_static->type=$objp->fk_product_type; + $product_static->id=$objp->fk_product; + $product_static->ref=$objp->ref; + $product_static->libelle=$objp->product; + $text=$product_static->getNomUrl(1); $text.= ' - '.$objp->product; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); - //print $description; print $html->textwithtooltip($text,$description,3,'','',$i); + + // Show range print_date_range($objp->date_start,$objp->date_end); - if ($conf->global->PRODUIT_DESC_IN_FORM) - { - print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; - } + + // Add description in form + if ($conf->global->PRODUIT_DESC_IN_FORM) print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; print '
'; print ''; // ancre pour retourner sur la ligne + + // Show product and description if ($objp->fk_product > 0) { print ''; - print ''; - if ($objp->fk_product_type==1) print img_object($langs->trans('ShowService'),'service'); - else print img_object($langs->trans('ShowProduct'),'product'); - print ' '.$objp->ref.''; - print ' - '.nl2br($objp->product); + $product_static->type=$objp->fk_product_type; + $product_static->id=$objp->fk_product; + $product_static->ref=$objp->ref; + $product_static->libelle=$objp->product; + $text=$product_static->getNomUrl(1); + $text.= ' - '.$objp->product; + print $text; print '
'; } - // éditeur wysiwyg + else + { + // TODO Select type (service or product) + + } + + // Description - Editor wysiwyg if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); @@ -2849,10 +2870,16 @@ else print ''; } print '
'; print $html->select_tva('tva_tx',$objp->tva_taux,$mysoc,$soc,'',$objp->info_bits); print ''; if (($objp->info_bits & 2) != 2) { @@ -2860,6 +2887,7 @@ else } else print ' '; print ''; if (($objp->info_bits & 2) != 2) { @@ -2867,6 +2895,7 @@ else } else print ' '; print ''; print '
 
'; - // éditeur wysiwyg + // TODO Select type (product or service) + + // Editeur wysiwyg if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); @@ -2931,7 +2962,6 @@ else } print ''; - $html->select_tva('tva_tx',$conf->defaulttx,$mysoc,$soc); print '
'.$fields['link'].''; if ($fields['pid']) { @@ -289,15 +298,17 @@ else $product_static->ref=$fields['pref']; $product_static->type=$fields['ptype']; print $product_static->getNomUrl(1); - if ($fields['descr']) print ' - '; + if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); } else { - if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); + if ($type) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); - print $text.' '; + print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + + // Show range + print_date_range($fields['ddate_start'],$fields['ddate_end']); } - print dol_trunc(dol_string_nohtmltag($fields['descr']),16); print ''; print price($fields['totalht']); - if ($fields['ftotal_ttc']) + if (price2num($fields['ftotal_ttc'])) { //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); @@ -318,33 +329,36 @@ else $ratiopaymentinvoice=1; if ($modetax == 0) { - if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); print ''; //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; if ($fields['payment_amount'] && $fields['ftotal_ttc']) { - $payment_static->rowid=$fields['payment_id']; + $payment_static->id=$fields['payment_id']; print $payment_static->getNomUrl(2); } - if ($fields['ptype'] == 0) + if ($type == 0) { print $langs->trans("NotUsedForGoods"); } - else print $fields['payment_amount']; - if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + else { + print $fields['payment_amount']; + if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + } print ''; $temp_ht=$fields['totalht']; - if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; print price(price2num($temp_ht,'MT')); print ''; - $temp_vat=$fields['vat']*$ratiopaymentinvoice; + $temp_vat=$fields['vat']; + if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice; print price(price2num($temp_vat,'MT')); //print price($fields['vat']); print '
'.$fields['link'].''; if ($fields['pid']) { @@ -412,22 +433,25 @@ else $product_static->ref=$fields['pref']; $product_static->type=$fields['ptype']; print $product_static->getNomUrl(1); - if ($fields['descr']) print ' - '; + if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); } else { - if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service'); + if ($type) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); - print $text.' '; + print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + + // Show range + print_date_range($fields['ddate_start'],$fields['ddate_end']); } - print dol_trunc($fields['descr'],24).''; print price($fields['totalht']); - if ($fields['ftotal_ttc']) + if (price2num($fields['ftotal_ttc'])) { //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); @@ -440,32 +464,36 @@ else $ratiopaymentinvoice=1; if ($modetax == 0) { - if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); print ''; if ($fields['payment_amount'] && $fields['ftotal_ttc']) { - $paymentfourn_static->rowid=$fields['payment_id']; + $paymentfourn_static->id=$fields['payment_id']; print $paymentfourn_static->getNomUrl(2); } - if ($fields['ptype'] == 0) + if ($type == 0) { print $langs->trans("NotUsedForGoods"); } - else print $fields['payment_amount']; - if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + else + { + print $fields['payment_amount']; + if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + } print ''; $temp_ht=$fields['totalht']; - if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; print price(price2num($temp_ht,'MT')); print ''; - $temp_vat=$fields['vat']*$ratiopaymentinvoice; + $temp_vat=$fields['vat']; + if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice; print price(price2num($temp_vat,'MT')); //print price($fields['vat']); print '
'.$fac->lignes[$i]->description.''.vatrate($fac->lignes[$i]->tva_taux).'%
'; /* - * Liste des paiements + * List of payments */ print '
'; $sql = 'SELECT '.$db->pdate('datep').' as dp, pf.amount,'; @@ -774,7 +774,7 @@ else /* - * Lignes + * Lines of invoice */ print '
'; print ''; @@ -836,7 +836,7 @@ else if ($fac->lignes[$i]->fk_product) { $productstatic->id=$fac->lignes[$i]->fk_product; - $productstatic->type=1; + $productstatic->type=$fac->lignes[$i]->product_type; //$productstatic->ref=$fac->lignes[$i]->ref; //print $productstatic->getNomUrl(1).' ('.$fac->lignes[$i]->ref_fourn.') - '.$fac->lignes[$i]->libelle; $productstatic->ref=$fac->lignes[$i]->libelle; diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 438fed41ee5..0b0ea9bcfcb 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -2407,7 +2407,7 @@ function dol_string_nohtmltag($StringHtml,$removelinefeed=1) { $temp = str_replace(" "," ",$temp); } - $CleanString = $temp; + $CleanString = trim($temp); return $CleanString; } diff --git a/htdocs/lib/tax.lib.php b/htdocs/lib/tax.lib.php index b6ec98a415a..63328958998 100644 --- a/htdocs/lib/tax.lib.php +++ b/htdocs/lib/tax.lib.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2006-2007 Yannick Warnier * * This program is free software; you can redistribute it and/or modify @@ -18,11 +18,11 @@ */ /** - \file htdocs/lib/tax.lib.php - \ingroup tax - \brief Library for tax module - \version $Id$ -*/ + * \file htdocs/lib/tax.lib.php + * \ingroup tax + * \brief Library for tax module + * \version $Id$ + */ /** @@ -143,7 +143,7 @@ function vat_by_thirdparty($db, $y, $modetax, $direction) * This function also accounts recurrent invoices * \param db Database handler object * \param y Year - * \param q Year quarter (1-4) + * \param q Period. If 1-4, it's year quarter. * \param modetax 0 or 1 (option vat on debit) * \param direction 'sell' or 'buy' * \return array List of quarters with vat @@ -196,7 +196,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) if ($conf->global->MAIN_MODULE_COMPTABILITE) { $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.type, f.total_ttc as ftotal_ttc,"; + $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,"; $sql.= " 0 as payment_id, 0 as payment_amount"; $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; @@ -207,7 +208,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) $sql.= " AND f.rowid = d.".$fk_facture; $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; - $sql.= " AND d.product_type = 0"; // Limit to products + $sql.= " AND (d.product_type = 0"; // Limit to products + $sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of service $sql.= " ORDER BY d.rowid, d.".$fk_facture; } } @@ -227,7 +229,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) { // Tva sur factures payés (should be on shipment, done on payment instead !) $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.type, f.total_ttc as ftotal_ttc,"; + $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,"; $sql.= " 0 as payment_id, 0 as payment_amount"; // $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount"; @@ -245,7 +248,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) // $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; - $sql.= " AND d.product_type = 0"; // Limit to products + $sql.= " AND (d.product_type = 0"; // Limit to products + $sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of service $sql.= " ORDER BY d.rowid, d.".$fk_facture; } } @@ -254,8 +258,9 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) if ($sql && $sql=='TODO') return -2; if ($sql && $sql!='TODO') { - dol_syslog("Client::vat_by_quarter sql=".$sql); - $resql = $db->query($sql); + dol_syslog("Tax.lib.php::vat_by_quarter sql=".$sql); + + $resql = $db->query($sql); if ($resql) { $rate = -1; @@ -273,6 +278,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) } $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; + $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); + $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); $list[$assoc['rate']]['facid'][] = $assoc['facid']; $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; @@ -320,7 +327,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) if ($conf->global->MAIN_MODULE_COMPTABILITE) { $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.type, f.total_ttc as ftotal_ttc,"; + $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,"; $sql.= " 0 as payment_id, 0 as payment_amount"; $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; @@ -331,7 +339,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) $sql.= " AND f.rowid = d.".$fk_facture; $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; - $sql.= " AND d.product_type = 1"; // Limit to services + $sql.= " AND (d.product_type = 1"; // Limit to services + $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service $sql.= " ORDER BY d.rowid, d.".$fk_facture; } } @@ -351,7 +360,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) { // Tva sur factures payés (should be on payment) $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.type, f.total_ttc as ftotal_ttc,"; + $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,"; $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount"; $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; @@ -366,7 +376,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) $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 + $sql.= " AND (d.product_type = 1"; // Limit to services + $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid"; } } @@ -375,7 +386,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) if ($sql && $sql=='TODO') return -2; if ($sql && $sql!='TODO') { - dol_syslog("Client::vat_by_quarter sql=".$sql); + dol_syslog("Tax.lib.php::vat_by_quarter sql=".$sql); $resql = $db->query($sql); if ($resql) { @@ -394,6 +405,8 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction) } $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; + $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); + $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); $list[$assoc['rate']]['facid'][] = $assoc['facid']; $list[$assoc['rate']]['facnum'][] = $assoc['facnum'];