32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
39$langs->loadlangs(array(
'companies',
'other',
'bills',
'compta'));
41$date_startmonth =
GETPOST(
'date_startmonth');
42$date_startday =
GETPOST(
'date_startday');
43$date_startyear =
GETPOST(
'date_startyear');
44$date_endmonth =
GETPOST(
'date_endmonth');
45$date_endday =
GETPOST(
'date_endday');
46$date_endyear =
GETPOST(
'date_endyear');
49if ($user->socid > 0) {
50 $socid = $user->socid;
52if (isModEnabled(
'comptabilite')) {
55if (isModEnabled(
'accounting')) {
56 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
58$hookmanager->initHooks([
'purchasejournallist']);
71$morequery =
'&date_startyear='.$date_startyear.
'&date_startmonth='.$date_startmonth.
'&date_startday='.$date_startday.
'&date_endyear='.$date_endyear.
'&date_endmonth='.$date_endmonth.
'&date_endday='.$date_endday;
73llxHeader(
'', $langs->trans(
"PurchasesJournal"),
'',
'', 0, 0,
'',
'', $morequery);
80$pastmonthyear = $year_current;
86$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
87$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
89if (empty($date_start) || empty($date_end)) {
94$name = $langs->trans(
"PurchasesJournal");
98$description = $langs->trans(
"DescPurchasesJournal").
'<br>';
100 $description .= $langs->trans(
"DepositsAreNotIncluded");
102 $description .= $langs->trans(
"DepositsAreIncluded");
104$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
106report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink);
112$sql =
"SELECT f.rowid, f.ref_supplier, f.type, f.datef, f.libelle as label,";
113$sql .=
" fd.total_ttc, fd.tva_tx, fd.total_ht, fd.tva as total_tva, fd.product_type, fd.localtax1_tx, fd.localtax2_tx, fd.total_localtax1, fd.total_localtax2,";
114$sql .=
" s.rowid as socid, s.nom as name, s.code_compta_fournisseur,";
115$sql .=
" p.rowid as pid, p.ref as ref, p.accountancy_code_buy,";
116$sql .=
" ct.accountancy_code_buy as account_tva, ct.recuperableonly";
117$sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as fd";
118$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_tva as ct ON fd.tva_tx = ct.taux AND fd.info_bits = ct.recuperableonly AND ct.fk_pays = ".((int) $idpays);
119$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
120$sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
121$sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
122$sql .=
" WHERE f.fk_statut > 0 AND f.entity IN (".getEntity(
'invoice').
")";
124 $sql .=
" AND f.type IN (0,1,2)";
126 $sql .=
" AND f.type IN (0,1,2,3)";
128if ($date_start && $date_end) {
129 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
133if (in_array($db->type, array(
'mysql',
'mysqli'))) {
134 $db->query(
'SET SQL_BIG_SELECTS=1');
137$result = $db->query($sql);
139 $num = $db->num_rows($result);
141 $cptfour = ((
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER') !=
"") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans(
"CodeNotDef"));
142 $cpttva = (
getDolGlobalString(
'ACCOUNTING_VAT_BUY_ACCOUNT') ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
148 $tablocaltax1 = array();
149 $tablocaltax2 = array();
150 $tabcompany = array();
154 $obj = $db->fetch_object($result);
156 $compta_soc = (($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $cptfour);
157 $compta_prod = $obj->accountancy_code_buy;
158 if (empty($compta_prod)) {
159 if ($obj->product_type == 0) {
160 $compta_prod = (
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT') ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
162 $compta_prod = (
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT') ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
165 $compta_tva = (!empty($obj->account_tva) ? $obj->account_tva : $cpttva);
166 $compta_localtax1 = (!empty($obj->account_localtax1) ? $obj->account_localtax1 : $langs->trans(
"CodeNotDef"));
167 $compta_localtax2 = (!empty($obj->account_localtax2) ? $obj->account_localtax2 : $langs->trans(
"CodeNotDef"));
170 $compta_localtax1 = (!empty($account_localtax1[2]) ? $account_localtax1[2] : $langs->trans(
"CodeNotDef"));
172 $compta_localtax2 = (!empty($account_localtax2[2]) ? $account_localtax2[2] : $langs->trans(
"CodeNotDef"));
174 $tabfac[$obj->rowid][
"date"] = $obj->datef;
175 $tabfac[$obj->rowid][
"ref"] = $obj->ref_supplier;
176 $tabfac[$obj->rowid][
"type"] = $obj->type;
177 $tabfac[$obj->rowid][
"lib"] = $obj->label;
178 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
179 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
180 if ($obj->recuperableonly != 1) {
181 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
183 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
184 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
185 $tabcompany[$obj->rowid] = array(
'id'=>$obj->socid,
'name'=>$obj->name);
196print
'<table class="liste noborder centpercent">';
197print
"<tr class=\"liste_titre\">";
199print
"<td>".$langs->trans(
"Date").
"</td>";
200print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
201print
"<td>".$langs->trans(
"Account").
"</td>";
202print
"<td>".$langs->trans(
"Type").
"</td>";
203print
"<td class='right'>".$langs->trans(
"AccountingDebit").
"</td>";
204print
"<td class='right'>".$langs->trans(
"AccountingCredit").
"</td>";
211foreach ($tabfac as $key => $val) {
212 $invoicestatic->id = $key;
213 $invoicestatic->ref = $val[
"ref"];
214 $invoicestatic->type = $val[
"type"];
216 $companystatic->id = $tabcompany[$key][
'id'];
217 $companystatic->name = $tabcompany[$key][
'name'];
221 'var' => $tabht[$key],
222 'label' => $langs->trans(
'Products'),
225 'var' => $tabtva[$key],
226 'label' => $langs->trans(
'VAT')
229 'var' => $tablocaltax1[$key],
230 'label' => $langs->transcountry(
'LT1', $mysoc->country_code)
233 'var' => $tablocaltax2[$key],
234 'label' => $langs->transcountry(
'LT2', $mysoc->country_code)
237 'var' => $tabttc[$key],
238 'label' => $langs->trans(
'ThirdParty').
' ('.$companystatic->getNomUrl(0,
'supplier', 16).
')',
244 foreach ($lines as $line) {
245 foreach ($line[
'var'] as $k => $mt) {
246 if (isset($line[
'nomtcheck']) || $mt) {
247 print
'<tr class="oddeven">';
248 print
"<td>".dol_print_date($db->jdate($val[
"date"])).
"</td>";
249 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
250 print
"<td>".$k.
"</td><td>".$line[
'label'].
"</td>";
252 if (isset($line[
'inv'])) {
253 print
'<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
254 print
'<td class="right">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
256 print
'<td class="right">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
257 print
'<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage suppliers invoices.
Class to manage suppliers.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.