if($modetax==1)// Option vat on delivery for goods (payment) and debit invoice for services
{
// 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="SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate 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.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
else// Option vat on delivery for goods (payments) and payments for services
{
// 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="SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate 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.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef as date_f, s.nom as company_name, s.rowid as company_id,";
if($modetax==1)// Option vat on delivery for goods (payment) and debit invoice for services
{
// 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="SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate 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.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
else// Option vat on delivery for goods (payments) and payments for services
{
// 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="SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate 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.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
$sql="SELECT e.rowid, d.product_type as dtype, e.rowid 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, e.note_private as descr,";
$sql="SELECT e.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
$sql.=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
$sql.=" e.date_debut as date_start, e.date_fin as date_end,";
$sql.=" e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, s.nom as company_name, s.rowid as company_id, d.fk_c_type_fees as type,";