From 5ed79800e0924dda12e5f2112c072a4e1b142c62 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sat, 5 Nov 2016 07:48:42 +0100 Subject: [PATCH 1/4] Begin to wok on Vat expense report integration in reports --- htdocs/compta/tva/index.php | 14 +- htdocs/compta/tva/quadri_detail.php | 245 +++++++++++++++--- htdocs/core/lib/tax.lib.php | 135 ++++++++++ .../mysql/tables/llx_expensereport.sql | 14 +- 4 files changed, 360 insertions(+), 48 deletions(-) diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index 30d9655acc8..9413313ff45 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -3,7 +3,8 @@ * Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2014 Ferran Marcet + * Copyright (C) 2014 Ferran Marcet + * Copyright (C) 2016 Alexandre Spangaro * * 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 @@ -20,8 +21,8 @@ */ /** - * \file htdocs/compta/tva/index.php - * \ingroup tax + * \file htdocs/compta/tva/index.php + * \ingroup tax * \brief Index page of VAT reports */ require '../../main.inc.php'; @@ -145,11 +146,12 @@ $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); + $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); + $coll_listexpensereport = vat_by_date($db, $y, 0, 0, 0, $modetax, 'expensereport', $m); $action = "tva"; - $object = array(&$coll_listsell, &$coll_listbuy); + $object = array(&$coll_listsell, &$coll_listbuy, &$coll_listexpensereport); $parameters["mode"] = $modetax; $parameters["year"] = $y; $parameters["month"] = $m; diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 6ebaee8ecd5..da6af3e2cff 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -3,7 +3,8 @@ * Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2013 Laurent Destailleur * Copyright (C) 2006-2007 Yannick Warnier - * Copyright (C) 2014 Ferran Marcet + * Copyright (C) 2014 Ferran Marcet + * Copyright (C) 2016 Alexandre Spangaro * * 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 @@ -36,11 +37,14 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php'; $langs->load("bills"); $langs->load("compta"); $langs->load("companies"); $langs->load("products"); +$langs->load("trips"); $langs->load("other"); // Date range @@ -111,9 +115,11 @@ $form=new Form($db); $company_static=new Societe($db); $invoice_customer=new Facture($db); $invoice_supplier=new FactureFournisseur($db); +$expensereport=new ExpenseReport($db); $product_static=new Product($db); $payment_static=new Paiement($db); $paymentfourn_static=new PaiementFourn($db); +$paymentexpensereport_static=new PaymentExpenseReport($db); //print load_fiche_titre($langs->trans("VAT"),""); @@ -149,16 +155,26 @@ if ($modetax==1) // Calculate on invoice for goods and services $builddate=time(); //$exportlink=$langs->trans("NotYetAvailable"); + // Customers invoices $elementcust=$langs->trans("CustomersInvoices"); $productcust=$langs->trans("ProductOrService"); $amountcust=$langs->trans("AmountHT"); $vatcust=$langs->trans("VATReceived"); if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')'; + + // Suppliers invoices $elementsup=$langs->trans("SuppliersInvoices"); $productsup=$langs->trans("ProductOrService"); $amountsup=$langs->trans("AmountHT"); $vatsup=$langs->trans("VATPaid"); if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')'; + + // Expense reports + $elementexpensereport=$langs->trans("ExpenseReports"); + $fees=$langs->trans("Fees"); + $amountexpensereport=$langs->trans("AmountHT"); + $vatexpensereport=$langs->trans("VATPaid"); + if ($mysoc->tva_assuj) $vatexpensereport.=' ('.$langs->trans("ToGetBack").')'; } if ($modetax==0) // Invoice for goods, payment for services { @@ -185,26 +201,35 @@ if ($modetax==0) // Invoice for goods, payment for services $builddate=time(); //$exportlink=$langs->trans("NotYetAvailable"); + // Customers invoices $elementcust=$langs->trans("CustomersInvoices"); $productcust=$langs->trans("ProductOrService"); $amountcust=$langs->trans("AmountHT"); $vatcust=$langs->trans("VATReceived"); if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')'; + + // Suppliers invoices $elementsup=$langs->trans("SuppliersInvoices"); $productsup=$langs->trans("ProductOrService"); $amountsup=$langs->trans("AmountHT"); $vatsup=$langs->trans("VATPaid"); if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')'; + + // Expense reports + $elementexpensereport=$langs->trans("ExpenseReports"); + $fees=$langs->trans("Fees"); + $amountexpensereport=$langs->trans("AmountHT"); + $vatexpensereport=$langs->trans("VATPaid"); + if ($mysoc->tva_assuj) $vatexpensereport.=' ('.$langs->trans("ToGetBack").')'; } report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode); $vatcust=$langs->trans("VATReceived"); $vatsup=$langs->trans("VATPaid"); - +$vatexpensereport=$langs->trans("VATPaid"); // VAT Received and paid - -echo ''; +print '
'; $y = $year_current; $total = 0; @@ -242,21 +267,21 @@ else $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id]; $invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id]; $x_both[$my_coll_rate]['coll']['detail'][] = array( - 'id' =>$x_coll[$my_coll_rate]['facid'][$id], - 'descr' =>$x_coll[$my_coll_rate]['descr'][$id], - 'pid' =>$x_coll[$my_coll_rate]['pid'][$id], - 'pref' =>$x_coll[$my_coll_rate]['pref'][$id], - 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id], - 'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id], + 'id' =>$x_coll[$my_coll_rate]['facid'][$id], + 'descr' =>$x_coll[$my_coll_rate]['descr'][$id], + 'pid' =>$x_coll[$my_coll_rate]['pid'][$id], + 'pref' =>$x_coll[$my_coll_rate]['pref'][$id], + 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id], + 'payment_id' =>$x_coll[$my_coll_rate]['payment_id'][$id], 'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id], - 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id], - 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id], - 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id], - 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id], - 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id], - 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], - 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], - 'link' =>$invoice_customer->getNomUrl(1,'',12)); + '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)); } } // tva paid @@ -276,21 +301,21 @@ else $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; $invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id]; $x_both[$my_paye_rate]['paye']['detail'][] = array( - 'id' =>$x_paye[$my_paye_rate]['facid'][$id], - 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], - 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], - 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], - 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], - 'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id], + 'id' =>$x_paye[$my_paye_rate]['facid'][$id], + 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], + 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], + 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], + 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], + 'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id], 'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id], - 'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), - 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), - 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], - 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id], - 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], - 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), - 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], - 'link' =>$invoice_supplier->getNomUrl(1,'',12)); + 'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), + 'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), + 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], + 'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id], + 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], + 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), + 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], + 'link' =>$invoice_supplier->getNomUrl(1,'',12)); } } //now we have an array (x_both) indexed by rates for coll and paye @@ -320,18 +345,18 @@ else print ''; print ''; print ''; - + $action = "tvadetail"; $parameters["mode"] = $modetax; $parameters["start"] = $date_start; $parameters["end"] = $date_end; $parameters["type"] = 'vat'; - + $object = array(&$x_coll, &$x_paye, &$x_both); // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('externalbalance')); $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks - + foreach(array_keys($x_coll) as $rate) { $subtot_coll_total_ht = 0; @@ -625,6 +650,156 @@ else print ''; } + // Blank line + print ''; + + // Expense reports + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''."\n"; + + foreach(array_keys($x_paye) as $rate) + { + $subtot_paye_total_ht = 0; + $subtot_paye_vat = 0; + + if(is_array($x_both[$rate]['paye']['detail'])) + { + $var=true; + print ""; + print ''; + 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 + print ''; + + // Total HT + if ($modetax == 0) + { + print ''; + } + + // Payment + $ratiopaymentinvoice=1; + if ($modetax == 0) + { + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + print ''; + } + + // VAT paid + print ''; + + // VAT + print ''; + print ''; + + $subtot_paye_total_ht += $temp_ht; + $subtot_paye_vat += $temp_vat; + $x_paye_sum += $temp_vat; + } + } + // Total suppliers for this vat rate + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''; + } + + if (count($x_paye) == 0) // Show a total ine if nothing shown + { + print ''; + print ''; + print ''; + if ($modetax == 0) + { + print ''; + print ''; + } + print ''; + print ''; + print ''; + } + print '
'.$langs->trans("AmountHTVATRealReceived").''.$vatcust.'
 
'.$elementexpensereport.''.$fees.''.$amountexpensereport.''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'.$langs->trans("AmountHTVATRealPaid").''.$vatexpensereport.'
'.$langs->trans("Rate").': '.vatrate($rate).'%
'.$fields['link'].''; + if ($fields['pid']) + { + $product_static->id=$fields['pid']; + $product_static->ref=$fields['pref']; + $product_static->type=$fields['ptype']; + print $product_static->getNomUrl(1); + if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + } + else + { + if ($type) $text = img_object($langs->trans('Service'),'service'); + else $text = img_object($langs->trans('Product'),'product'); + print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); + + // Show range + print_date_range($fields['ddate_start'],$fields['ddate_end']); + } + print ''; + print price($fields['totalht']); + if (price2num($fields['ftotal_ttc'])) + { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print ''; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) + { + $paymentfourn_static->id=$fields['payment_id']; + print $paymentfourn_static->getNomUrl(2); + } + if ($type == 0) + { + print $langs->trans("NotUsedForGoods"); + } + else + { + print price($fields['payment_amount']); + if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; + } + print ''; + $temp_ht=$fields['totalht']; + if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + print price(price2num($temp_ht,'MT'),1); + print ''; + $temp_vat=$fields['vat']; + if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice; + print price(price2num($temp_vat,'MT'),1); + //print price($fields['vat']); + print '
 '.$langs->trans("Total").':  '.price(price2num($subtot_paye_total_ht,'MT')).''.price(price2num($subtot_paye_vat,'MT')).'
 '.$langs->trans("Total").':  '.price(price2num(0,'MT')).''.price(price2num(0,'MT')).'
'; // Total to pay diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index 740bb223cba..78ffb952acf 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -230,6 +230,17 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $paymentfacturetable='paiementfourn_facturefourn'; $invoicefieldref='ref'; } + if ($direction == 'expensereport') + { + $expensereporttable='expensereport'; + $expensereportdettable='expensereport_det'; + $fk_expensereport='fk_expensereport'; + $total_tva='total_tva'; + $total_localtax1='total_localtax1'; + $total_localtax2='total_localtax2'; + $paymenttable='payment_expensereport'; + $expensereportfieldref='ref'; + } // CAS DES BIENS @@ -515,6 +526,130 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, } } + // Expense Report + + // Define sql request + $sql=''; + if ($modetax == 1) // Option vat on delivery for goods (payment) and debit invoice for services + { + // Count on invoice date + $sql = "SELECT erd.rowid, erd.fk_c_type_fees as fees_type, erd.".$fk_expensereport." as erid, erd.tva_tx as rate, erd.total_ht as total_ht, erd.total_ttc as total_ttc, erd.".$total_tva." as total_vat, erd.comments as descr, erd.date as dateexpensereport,"; + $sql .=" erd.".$total_localtax1." as total_localtax1, erd.".$total_localtax2." as total_localtax2, "; + $sql.= " er.".$expensereportfieldref." as ernum, er.total_ttc as ertotal_ttc, u.lastname as user_lastname, u.firstname as user_firstname, u.rowid as user_id,"; + // $sql.= " er.date_debut as date_start, er.date_fin as date_end,"; + $sql.= " f.id as fid, f.label as flabel"; + $sql.= " FROM ".MAIN_DB_PREFIX.$expensereporttable." as er,"; + $sql.= " ".MAIN_DB_PREFIX.$expensereportdettable." as erd," ; + $sql.= " ".MAIN_DB_PREFIX."user as u"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as f on erd.fk_c_type_fees = f.id"; + $sql.= " WHERE er.entity = " . $conf->entity; + $sql.= " AND u.rowid = er.fk_user_author"; + $sql.= " AND er.fk_statut in (5,6)"; // Validated or paid (partially or completely) + $sql.= " AND er.rowid = erd.".$fk_expensereport; + if ($y && $m) + { + $sql.= " AND erd.date >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; + $sql.= " AND erd.date <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; + } + else if ($y) + { + $sql.= " AND erd.date >= '".$db->idate(dol_get_first_day($y,1,false))."'"; + $sql.= " AND erd.date <= '".$db->idate(dol_get_last_day($y,12,false))."'"; + } + if ($q) $sql.= " AND (date_format(erd.date,'%m') > ".(($q-1)*3)." AND date_format(erd.date,'%m') <= ".($q*3).")"; + if ($date_start && $date_end) $sql.= " AND erd.date >= '".$db->idate($date_start)."' AND erd.date <= '".$db->idate($date_end)."'"; + $sql.= " ORDER BY erd.rowid, erd.".$fk_expensereport; + } + else // Option vat on delivery for goods (payments) and payments for services + { + // Count on payments date + $sql = "SELECT erd.rowid, erd.fk_c_type_fees as fees_type, erd.".$fk_expensereport." as erid, erd.tva_tx as rate, erd.total_ht as total_ht, erd.total_ttc as total_ttc, erd.".$total_tva." as total_vat, erd.comments as descr, erd.date as dateexpensereport,"; + $sql .=" erd.".$total_localtax1." as total_localtax1, erd.".$total_localtax2." as total_localtax2, "; + $sql.= " er.".$expensereportfieldref." as ernum, er.total_ttc as ertotal_ttc, u.lastname as user_lastname, u.firstname as user_firstname, u.rowid as user_id,"; + // $sql.= " er.date_debut as date_start, er.date_start as date_end,"; + $sql.= " f.id as fid, f.label as flabel,"; + $sql.= " pa.rowid as payment_id, pa.amount as payment_amount"; + $sql.= " FROM ".MAIN_DB_PREFIX.$expensereporttable." as er,"; + $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; + $sql.= " ".MAIN_DB_PREFIX."user as u,"; + $sql.= " ".MAIN_DB_PREFIX.$expensereportdettable." as erd"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as f on erd.fk_c_type_fees = f.id"; + $sql.= " WHERE er.entity = " . $conf->entity; + $sql.= " AND er.fk_statut in (5,6)"; // Paid (partially or completely) + $sql.= " AND er.rowid = erd.".$fk_expensereport; + $sql.= " AND u.rowid = er.fk_user_author"; + $sql.= " AND pa.rowid = er.".$fk_expensereport; + if ($y && $m) + { + $sql.= " AND erd.date >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; + $sql.= " AND erd.date <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; + } + else if ($y) + { + $sql.= " AND erd.date >= '".$db->idate(dol_get_first_day($y,1,false))."'"; + $sql.= " AND erd.date <= '".$db->idate(dol_get_last_day($y,12,false))."'"; + } + if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; + if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'"; + $sql.= " ORDER BY er.rowid, erd.".$fk_expensereport; + } + + if (! $sql) + { + dol_syslog("Tax.lib.php::vat_by_date no accountancy module enabled".$sql,LOG_ERR); + return -1; // -1 = Not accountancy module enabled + } + if ($sql == 'TODO') return -2; // -2 = Feature not yet available + if ($sql != 'TODO') + { + dol_syslog("Tax.lib.php::vat_by_date", LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) + { + $rate = -1; + $oldrowid=''; + while($assoc = $db->fetch_array($resql)) + { + 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']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0; + if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0; + + $list[$assoc['rate']]['erdtotal_ttc'][] = $assoc['total_ttc']; + $list[$assoc['rate']]['ftype'][] = $assoc['fees_type']; + $list[$assoc['rate']]['erdate'][] = $assoc['dateexpensereport']; + $list[$assoc['rate']]['ulastname'][] = $assoc['user_lastname']; + $list[$assoc['rate']]['ufirstname'][] = $assoc['user_firstname']; + $list[$assoc['rate']]['uid'][] = $assoc['user_id']; + // $list[$assoc['rate']]['erddate_start'][] = $db->jdate($assoc['date_start']); + // $list[$assoc['rate']]['erddate_end'][] = $db->jdate($assoc['date_end']); + + $list[$assoc['rate']]['erid'][] = $assoc['erid']; + $list[$assoc['rate']]['ernum'][] = $assoc['ernum']; + $list[$assoc['rate']]['ertotal_ttc'][] = $assoc['ertotal_ttc']; + $list[$assoc['rate']]['descr'][] = $assoc['descr']; + + $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']]['fid'][] = $assoc['fid']; + $list[$assoc['rate']]['flabel'][] = $assoc['flabel']; + + $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; + $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; + + $rate = $assoc['rate']; + } + } + else + { + dol_print_error($db); + return -3; + } + } + return $list; } diff --git a/htdocs/install/mysql/tables/llx_expensereport.sql b/htdocs/install/mysql/tables/llx_expensereport.sql index a6f93d9cb37..a6b45daddf4 100755 --- a/htdocs/install/mysql/tables/llx_expensereport.sql +++ b/htdocs/install/mysql/tables/llx_expensereport.sql @@ -24,8 +24,8 @@ CREATE TABLE llx_expensereport ( ref_ext integer, total_ht double(24,8) DEFAULT 0, total_tva double(24,8) DEFAULT 0, - localtax1 double(24,8) DEFAULT 0, -- amount total localtax1 - localtax2 double(24,8) DEFAULT 0, -- amount total localtax2 + localtax1 double(24,8) DEFAULT 0, -- amount total localtax1 + localtax2 double(24,8) DEFAULT 0, -- amount total localtax2 total_ttc double(24,8) DEFAULT 0, date_debut date NOT NULL, date_fin date NOT NULL, @@ -42,14 +42,14 @@ CREATE TABLE llx_expensereport ( fk_user_approve integer DEFAULT NULL, fk_user_refuse integer DEFAULT NULL, fk_user_cancel integer DEFAULT NULL, - fk_statut integer NOT NULL, -- 1=brouillon, 2=validated (waiting approval), 4=canceled, 5=approved, 6=payed, 99=refused - fk_c_paiement integer DEFAULT NULL, -- deprecated - paid smallint default 0 NOT NULL, -- deprecated + fk_statut integer NOT NULL, -- 1=brouillon, 2=validated (waiting approval), 4=canceled, 5=approved, 6=payed, 99=refused + fk_c_paiement integer DEFAULT NULL, -- deprecated + paid smallint default 0 NOT NULL, -- deprecated note_public text, note_private text, detail_refuse varchar(255) DEFAULT NULL, detail_cancel varchar(255) DEFAULT NULL, - integration_compta integer DEFAULT NULL, -- not used + integration_compta integer DEFAULT NULL, -- not used fk_bank_account integer DEFAULT NULL, model_pdf varchar(50) DEFAULT NULL, @@ -61,6 +61,6 @@ CREATE TABLE llx_expensereport ( multicurrency_total_ttc double(24,8) DEFAULT 0, import_key varchar(14), - extraparams varchar(255) -- for other parameters with json format + extraparams varchar(255) -- for other parameters with json format ) ENGINE=innodb; From e13e66ce7ba79a35dd15908392b186fcc43884ea Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sat, 12 Nov 2016 07:40:08 +0100 Subject: [PATCH 2/4] Update works --- htdocs/compta/tva/index.php | 3 +- htdocs/core/lib/tax.lib.php | 221 ++++++++++++++++-------------------- 2 files changed, 96 insertions(+), 128 deletions(-) diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index 9413313ff45..d3c6bd172b4 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -148,10 +148,9 @@ 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); - $coll_listexpensereport = vat_by_date($db, $y, 0, 0, 0, $modetax, 'expensereport', $m); $action = "tva"; - $object = array(&$coll_listsell, &$coll_listbuy, &$coll_listexpensereport); + $object = array(&$coll_listsell, &$coll_listbuy); $parameters["mode"] = $modetax; $parameters["year"] = $y; $parameters["month"] = $m; diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index 78ffb952acf..0fc401f0280 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -230,17 +230,6 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $paymentfacturetable='paiementfourn_facturefourn'; $invoicefieldref='ref'; } - if ($direction == 'expensereport') - { - $expensereporttable='expensereport'; - $expensereportdettable='expensereport_det'; - $fk_expensereport='fk_expensereport'; - $total_tva='total_tva'; - $total_localtax1='total_localtax1'; - $total_localtax2='total_localtax2'; - $paymenttable='payment_expensereport'; - $expensereportfieldref='ref'; - } // CAS DES BIENS @@ -527,129 +516,109 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, } // Expense Report + if ($direction == 'buy') + { + // Define sql request + $sql=''; - // Define sql request - $sql=''; - if ($modetax == 1) // Option vat on delivery for goods (payment) and debit invoice for services - { - // Count on invoice date - $sql = "SELECT erd.rowid, erd.fk_c_type_fees as fees_type, erd.".$fk_expensereport." as erid, erd.tva_tx as rate, erd.total_ht as total_ht, erd.total_ttc as total_ttc, erd.".$total_tva." as total_vat, erd.comments as descr, erd.date as dateexpensereport,"; - $sql .=" erd.".$total_localtax1." as total_localtax1, erd.".$total_localtax2." as total_localtax2, "; - $sql.= " er.".$expensereportfieldref." as ernum, er.total_ttc as ertotal_ttc, u.lastname as user_lastname, u.firstname as user_firstname, u.rowid as user_id,"; - // $sql.= " er.date_debut as date_start, er.date_fin as date_end,"; - $sql.= " f.id as fid, f.label as flabel"; - $sql.= " FROM ".MAIN_DB_PREFIX.$expensereporttable." as er,"; - $sql.= " ".MAIN_DB_PREFIX.$expensereportdettable." as erd," ; - $sql.= " ".MAIN_DB_PREFIX."user as u"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as f on erd.fk_c_type_fees = f.id"; - $sql.= " WHERE er.entity = " . $conf->entity; - $sql.= " AND u.rowid = er.fk_user_author"; - $sql.= " AND er.fk_statut in (5,6)"; // Validated or paid (partially or completely) - $sql.= " AND er.rowid = erd.".$fk_expensereport; - if ($y && $m) - { - $sql.= " AND erd.date >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; - $sql.= " AND erd.date <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; - } - else if ($y) - { - $sql.= " AND erd.date >= '".$db->idate(dol_get_first_day($y,1,false))."'"; - $sql.= " AND erd.date <= '".$db->idate(dol_get_last_day($y,12,false))."'"; - } - if ($q) $sql.= " AND (date_format(erd.date,'%m') > ".(($q-1)*3)." AND date_format(erd.date,'%m') <= ".($q*3).")"; - if ($date_start && $date_end) $sql.= " AND erd.date >= '".$db->idate($date_start)."' AND erd.date <= '".$db->idate($date_end)."'"; - $sql.= " ORDER BY erd.rowid, erd.".$fk_expensereport; - } - else // Option vat on delivery for goods (payments) and payments for services - { - // Count on payments date - $sql = "SELECT erd.rowid, erd.fk_c_type_fees as fees_type, erd.".$fk_expensereport." as erid, erd.tva_tx as rate, erd.total_ht as total_ht, erd.total_ttc as total_ttc, erd.".$total_tva." as total_vat, erd.comments as descr, erd.date as dateexpensereport,"; - $sql .=" erd.".$total_localtax1." as total_localtax1, erd.".$total_localtax2." as total_localtax2, "; - $sql.= " er.".$expensereportfieldref." as ernum, er.total_ttc as ertotal_ttc, u.lastname as user_lastname, u.firstname as user_firstname, u.rowid as user_id,"; - // $sql.= " er.date_debut as date_start, er.date_start as date_end,"; - $sql.= " f.id as fid, f.label as flabel,"; - $sql.= " pa.rowid as payment_id, pa.amount as payment_amount"; - $sql.= " FROM ".MAIN_DB_PREFIX.$expensereporttable." as er,"; - $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; - $sql.= " ".MAIN_DB_PREFIX."user as u,"; - $sql.= " ".MAIN_DB_PREFIX.$expensereportdettable." as erd"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as f on erd.fk_c_type_fees = f.id"; - $sql.= " WHERE er.entity = " . $conf->entity; - $sql.= " AND er.fk_statut in (5,6)"; // Paid (partially or completely) - $sql.= " AND er.rowid = erd.".$fk_expensereport; - $sql.= " AND u.rowid = er.fk_user_author"; - $sql.= " AND pa.rowid = er.".$fk_expensereport; - if ($y && $m) - { - $sql.= " AND erd.date >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; - $sql.= " AND erd.date <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; - } - else if ($y) - { - $sql.= " AND erd.date >= '".$db->idate(dol_get_first_day($y,1,false))."'"; - $sql.= " AND erd.date <= '".$db->idate(dol_get_last_day($y,12,false))."'"; - } - if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; - if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'"; - $sql.= " ORDER BY er.rowid, erd.".$fk_expensereport; - } + // Count on payments date + $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 .=" 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,"; + $sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,"; + $sql.= " ".MAIN_DB_PREFIX."expensereport_det as d,"; + $sql.= " ".MAIN_DB_PREFIX."expensereport as e,"; + $sql.= " ".MAIN_DB_PREFIX."payment_expensereport as p"; + $sql.= " WHERE e.entity = " . $conf->entity; + $sql.= " AND e.fk_statut in (6)"; + $sql.= " AND e.rowid = p.fk_expensereport"; + $sql.= " AND s.rowid = e.entity"; + $sql.= " AND d.fk_expensereport = e.rowid"; + if ($y && $m) + { + $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; + $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; + } + else if ($y) + { + $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; + $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; + } + if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")"; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql.= " AND (d.product_type = -1"; + $sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service + $sql.= " ORDER BY e.rowid"; - if (! $sql) - { - dol_syslog("Tax.lib.php::vat_by_date no accountancy module enabled".$sql,LOG_ERR); - return -1; // -1 = Not accountancy module enabled - } - if ($sql == 'TODO') return -2; // -2 = Feature not yet available - if ($sql != 'TODO') - { - dol_syslog("Tax.lib.php::vat_by_date", LOG_DEBUG); - $resql = $db->query($sql); - if ($resql) - { - $rate = -1; - $oldrowid=''; - while($assoc = $db->fetch_array($resql)) - { - 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']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0; - if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0; + if (! $sql) + { + dol_syslog("Tax.lib.php::vat_by_date no accountancy module enabled".$sql,LOG_ERR); + return -1; // -1 = Not accountancy module enabled + } + if ($sql == 'TODO') return -2; // -2 = Feature not yet available + if ($sql != 'TODO') + { + dol_syslog("Tax.lib.php::vat_by_date", LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) + { + $rate = -1; + $oldrowid=''; + while($assoc = $db->fetch_array($resql)) + { + 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']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0; + if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0; - $list[$assoc['rate']]['erdtotal_ttc'][] = $assoc['total_ttc']; - $list[$assoc['rate']]['ftype'][] = $assoc['fees_type']; - $list[$assoc['rate']]['erdate'][] = $assoc['dateexpensereport']; - $list[$assoc['rate']]['ulastname'][] = $assoc['user_lastname']; - $list[$assoc['rate']]['ufirstname'][] = $assoc['user_firstname']; - $list[$assoc['rate']]['uid'][] = $assoc['user_id']; - // $list[$assoc['rate']]['erddate_start'][] = $db->jdate($assoc['date_start']); - // $list[$assoc['rate']]['erddate_end'][] = $db->jdate($assoc['date_end']); + if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid + { + $oldrowid=$assoc['rowid']; + $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; + $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; + $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; + } - $list[$assoc['rate']]['erid'][] = $assoc['erid']; - $list[$assoc['rate']]['ernum'][] = $assoc['ernum']; - $list[$assoc['rate']]['ertotal_ttc'][] = $assoc['ertotal_ttc']; - $list[$assoc['rate']]['descr'][] = $assoc['descr']; + $list[$assoc['rate']]['vat'] = $assoc['total_vat']; + $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; + $list[$assoc['rate']]['dtype'][] = 'ExpenseReportPayment'; + $list[$assoc['rate']]['datef'][] = $assoc['datef']; + $list[$assoc['rate']]['company_name'][] = $assoc['company_name']; + $list[$assoc['rate']]['company_id'][] = $assoc['company_id']; + $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); + $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); - $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']]['facid'][] = $assoc['facid']; + $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; + $list[$assoc['rate']]['type'][] = $assoc['type']; + $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; + $list[$assoc['rate']]['descr'][] = $assoc['descr']; - $list[$assoc['rate']]['fid'][] = $assoc['fid']; - $list[$assoc['rate']]['flabel'][] = $assoc['flabel']; + $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']]['payment_id'][] = $assoc['payment_id']; - $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; + $list[$assoc['rate']]['pid'][] = $assoc['pid']; + $list[$assoc['rate']]['pref'][] = $assoc['pref']; + $list[$assoc['rate']]['ptype'][] = 'ExpenseReportPayment'; - $rate = $assoc['rate']; - } - } - else - { - dol_print_error($db); - return -3; - } - } + $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; + $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; - return $list; + $rate = $assoc['rate']; + } + } + else + { + dol_print_error($db); + return -3; + } + } + } + + return $list; } From 1dcf02af3aea83ed16d2fcbddb3b831e47000de1 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sat, 12 Nov 2016 08:05:25 +0100 Subject: [PATCH 3/4] Correct some mistakes --- htdocs/compta/tva/index.php | 5 +- htdocs/compta/tva/quadri_detail.php | 271 +++++++--------------------- 2 files changed, 70 insertions(+), 206 deletions(-) diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index d3c6bd172b4..c9a65ac2f03 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -4,7 +4,6 @@ * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2014 Ferran Marcet - * Copyright (C) 2016 Alexandre Spangaro * * 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 @@ -146,8 +145,8 @@ $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); + $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); $action = "tva"; $object = array(&$coll_listsell, &$coll_listbuy); diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index da6af3e2cff..347fd606815 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -169,12 +169,6 @@ if ($modetax==1) // Calculate on invoice for goods and services $vatsup=$langs->trans("VATPaid"); if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')'; - // Expense reports - $elementexpensereport=$langs->trans("ExpenseReports"); - $fees=$langs->trans("Fees"); - $amountexpensereport=$langs->trans("AmountHT"); - $vatexpensereport=$langs->trans("VATPaid"); - if ($mysoc->tva_assuj) $vatexpensereport.=' ('.$langs->trans("ToGetBack").')'; } if ($modetax==0) // Invoice for goods, payment for services { @@ -215,12 +209,6 @@ if ($modetax==0) // Invoice for goods, payment for services $vatsup=$langs->trans("VATPaid"); if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')'; - // Expense reports - $elementexpensereport=$langs->trans("ExpenseReports"); - $fees=$langs->trans("Fees"); - $amountexpensereport=$langs->trans("AmountHT"); - $vatexpensereport=$langs->trans("VATPaid"); - if ($mysoc->tva_assuj) $vatexpensereport.=' ('.$langs->trans("ToGetBack").')'; } report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode); @@ -267,21 +255,21 @@ else $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id]; $invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id]; $x_both[$my_coll_rate]['coll']['detail'][] = array( - 'id' =>$x_coll[$my_coll_rate]['facid'][$id], - 'descr' =>$x_coll[$my_coll_rate]['descr'][$id], - 'pid' =>$x_coll[$my_coll_rate]['pid'][$id], - 'pref' =>$x_coll[$my_coll_rate]['pref'][$id], - 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id], - 'payment_id' =>$x_coll[$my_coll_rate]['payment_id'][$id], - 'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id], - 'ftotal_ttc' =>$x_coll[$my_coll_rate]['ftotal_ttc'][$id], - 'dtotal_ttc' =>$x_coll[$my_coll_rate]['dtotal_ttc'][$id], - 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id], - 'ddate_start' =>$x_coll[$my_coll_rate]['ddate_start'][$id], - 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id], - 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], - 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], - 'link' =>$invoice_customer->getNomUrl(1,'',12)); + 'id' =>$x_coll[$my_coll_rate]['facid'][$id], + 'descr' =>$x_coll[$my_coll_rate]['descr'][$id], + 'pid' =>$x_coll[$my_coll_rate]['pid'][$id], + 'pref' =>$x_coll[$my_coll_rate]['pref'][$id], + 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id], + 'payment_id' =>$x_coll[$my_coll_rate]['payment_id'][$id], + 'payment_amount' =>$x_coll[$my_coll_rate]['payment_amount'][$id], + 'ftotal_ttc' =>$x_coll[$my_coll_rate]['ftotal_ttc'][$id], + 'dtotal_ttc' =>$x_coll[$my_coll_rate]['dtotal_ttc'][$id], + 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id], + 'ddate_start' =>$x_coll[$my_coll_rate]['ddate_start'][$id], + 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id], + 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], + 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], + 'link' =>$invoice_customer->getNomUrl(1,'',12)); } } // tva paid @@ -297,25 +285,52 @@ else foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy) { - $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; - $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; - $invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id]; - $x_both[$my_paye_rate]['paye']['detail'][] = array( - 'id' =>$x_paye[$my_paye_rate]['facid'][$id], - 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], - 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], - 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], - 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], - 'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id], - 'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id], - 'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), - 'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), - 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], - 'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id], - 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], - 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), - 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], - 'link' =>$invoice_supplier->getNomUrl(1,'',12)); + // ExpenseReport + if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') + { + $expensereport->id=$x_paye[$my_paye_rate]['facid'][$id]; + $expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id]; + $expensereport->type=$x_paye[$my_paye_rate]['type'][$id]; + + $x_both[$my_paye_rate]['paye']['detail'][] = array( + 'id' =>$x_paye[$my_paye_rate]['facid'][$id], + 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], + 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], + 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], + 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], + 'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id], + 'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id], + 'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), + 'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), + 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], + 'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id], + 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], + 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), + 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], + 'link' =>img_object($langs->trans("ExpenseReports"),"trip").' '.$expensereport->getNomUrl(0,32)); + } + else + { + $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; + $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; + $invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id]; + $x_both[$my_paye_rate]['paye']['detail'][] = array( + 'id' =>$x_paye[$my_paye_rate]['facid'][$id], + 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], + 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], + 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], + 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], + 'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id], + 'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id], + 'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), + 'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), + 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], + 'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id], + 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], + 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), + 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], + 'link' =>$invoice_supplier->getNomUrl(1,'',12)); + } } } //now we have an array (x_both) indexed by rates for coll and paye @@ -399,12 +414,12 @@ else { if ($type) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); - if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) - { - if ($reg[1]=='DEPOSIT') $fields['descr']=$langs->transnoentitiesnoconv('Deposit'); - elseif ($reg[1]=='CREDIT_NOTE') $fields['descr']=$langs->transnoentitiesnoconv('CreditNote'); - else $fields['descr']=$langs->transnoentitiesnoconv($reg[1]); - } + if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) + { + if ($reg[1]=='DEPOSIT') $fields['descr']=$langs->transnoentitiesnoconv('Deposit'); + elseif ($reg[1]=='CREDIT_NOTE') $fields['descr']=$langs->transnoentitiesnoconv('CreditNote'); + else $fields['descr']=$langs->transnoentitiesnoconv($reg[1]); + } print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); // Show range @@ -635,157 +650,7 @@ else print ''; } - if (count($x_paye) == 0) // Show a total ine if nothing shown - { - print ''; - print ' '; - print ''.$langs->trans("Total").':'; - if ($modetax == 0) - { - print ' '; - print ' '; - } - print ''.price(price2num(0,'MT')).''; - print ''.price(price2num(0,'MT')).''; - print ''; - } - - // Blank line - print ' '; - - // Expense reports - print ''; - print ''.$elementexpensereport.''; - print ''.$fees.''; - if ($modetax == 0) - { - print ''.$amountexpensereport.''; - print ''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'; - } - print ''.$langs->trans("AmountHTVATRealPaid").''; - print ''.$vatexpensereport.''; - print ''."\n"; - - foreach(array_keys($x_paye) as $rate) - { - $subtot_paye_total_ht = 0; - $subtot_paye_vat = 0; - - if(is_array($x_both[$rate]['paye']['detail'])) - { - $var=true; - print ""; - print ''.$langs->trans("Rate").': '.vatrate($rate).'%'; - 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 ''.$fields['link'].''; - - // Description - print ''; - if ($fields['pid']) - { - $product_static->id=$fields['pid']; - $product_static->ref=$fields['pref']; - $product_static->type=$fields['ptype']; - print $product_static->getNomUrl(1); - if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); - } - else - { - if ($type) $text = img_object($langs->trans('Service'),'service'); - else $text = img_object($langs->trans('Product'),'product'); - print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); - - // Show range - print_date_range($fields['ddate_start'],$fields['ddate_end']); - } - print ''; - - // Total HT - if ($modetax == 0) - { - print ''; - print price($fields['totalht']); - if (price2num($fields['ftotal_ttc'])) - { - //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; - $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']); - //print ' ('.round($ratiolineinvoice*100,2).'%)'; - } - print ''; - } - - // Payment - $ratiopaymentinvoice=1; - if ($modetax == 0) - { - 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->id=$fields['payment_id']; - print $paymentfourn_static->getNomUrl(2); - } - if ($type == 0) - { - print $langs->trans("NotUsedForGoods"); - } - else - { - print price($fields['payment_amount']); - if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; - } - print ''; - } - - // VAT paid - print ''; - $temp_ht=$fields['totalht']; - if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice; - print price(price2num($temp_ht,'MT'),1); - print ''; - - // VAT - print ''; - $temp_vat=$fields['vat']; - if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice; - print price(price2num($temp_vat,'MT'),1); - //print price($fields['vat']); - print ''; - print ''; - - $subtot_paye_total_ht += $temp_ht; - $subtot_paye_vat += $temp_vat; - $x_paye_sum += $temp_vat; - } - } - // Total suppliers for this vat rate - print ''; - print ' '; - print ''.$langs->trans("Total").':'; - if ($modetax == 0) - { - print ' '; - print ' '; - } - print ''.price(price2num($subtot_paye_total_ht,'MT')).''; - print ''.price(price2num($subtot_paye_vat,'MT')).''; - print ''; - } - - if (count($x_paye) == 0) // Show a total ine if nothing shown + if (count($x_paye) == 0) // Show a total line if nothing shown { print ''; print ' '; From 8909b4111d206de9ca3023687646e7bdfc721fcd Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sat, 12 Nov 2016 10:41:57 +0100 Subject: [PATCH 4/4] Add options on getNomUrl --- htdocs/compta/tva/quadri_detail.php | 2 +- .../class/expensereport.class.php | 51 +++++++++++++++---- htdocs/langs/en_US/trips.lang | 1 + 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 347fd606815..27a44269110 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -307,7 +307,7 @@ else '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' =>img_object($langs->trans("ExpenseReports"),"trip").' '.$expensereport->getNomUrl(0,32)); + 'link' =>$expensereport->getNomUrl(1); } else { diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 8a49983eccf..f65f0119a85 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1164,25 +1164,56 @@ class ExpenseReport extends CommonObject /** * Return clicable name (with picto eventually) * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @return string String with URL + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $max Max length of shown ref + * @param int $short 1=Return just URL + * @param string $moretitle Add more text to title tooltip + * @param int $notooltip 1=Disable tooltip + * @return string String with URL */ - function getNomUrl($withpicto=0) + function getNomUrl($withpicto=0,$max=0,$short=0,$moretitle='',$notooltip=0) { - global $langs; + global $langs, $conf; $result=''; - $link = ''; - $linkend=''; + $url = DOL_URL_ROOT.'/expensereport/card.php?id='.$this->id; + + if ($short) return $url; $picto='trip'; + $label = '' . $langs->trans("ShowExpenseReport") . ''; + if (! empty($this->ref)) + $label .= '
' . $langs->trans('Ref') . ': ' . $this->ref; + if (! empty($this->total_ht)) + $label.= '
' . $langs->trans('AmountHT') . ': ' . price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); + if (! empty($this->total_tva)) + $label.= '
' . $langs->trans('VAT') . ': ' . price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); + if (! empty($this->total_ttc)) + $label.= '
' . $langs->trans('AmountTTC') . ': ' . price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); + if ($moretitle) $label.=' - '.$moretitle; - $label=$langs->trans("Show").': '.$this->ref; + $ref=$this->ref; + if (empty($ref)) $ref=$this->id; - if ($withpicto) $result.=($link.img_object($label,$picto).$linkend); - if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$link.$this->ref.$linkend; + $linkclose=''; + if (empty($notooltip)) + { + if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label=$langs->trans("ShowExpenseReport"); + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose.=' class="classfortooltip"'; + } + + $linkstart = ''; + $linkend=''; + + if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend.' '); + $result.=$linkstart.($max?dol_trunc($ref,$max):$ref).$linkend; return $result; } diff --git a/htdocs/langs/en_US/trips.lang b/htdocs/langs/en_US/trips.lang index 6a12588139d..900b424f3e7 100644 --- a/htdocs/langs/en_US/trips.lang +++ b/htdocs/langs/en_US/trips.lang @@ -1,6 +1,7 @@ # Dolibarr language file - Source file is en_US - trips ExpenseReport=Expense report ExpenseReports=Expense reports +ShowExpenseReport=Show expense report Trips=Expense reports TripsAndExpenses=Expenses reports TripsAndExpensesStatistics=Expense reports statistics