31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
38 $langs->loadlangs(array(
'companies',
'other',
'bills',
'compta'));
40 $date_startmonth =
GETPOST(
'date_startmonth');
41 $date_startday =
GETPOST(
'date_startday');
42 $date_startyear =
GETPOST(
'date_startyear');
43 $date_endmonth =
GETPOST(
'date_endmonth');
44 $date_endday =
GETPOST(
'date_endday');
45 $date_endyear =
GETPOST(
'date_endyear');
48 if ($user->socid > 0) $socid = $user->socid;
49 if (!empty($conf->comptabilite->enabled)) $result =
restrictedArea($user,
'compta',
'',
'',
'resultat');
50 if (!empty($conf->accounting->enabled)) $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
64 $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;
66 llxHeader(
'', $langs->trans(
"PurchasesJournal"),
'',
'', 0, 0,
'',
'', $morequery);
68 $form =
new Form($db);
70 $year_current = strftime(
"%Y",
dol_now());
71 $pastmonth = strftime(
"%m",
dol_now()) - 1;
72 $pastmonthyear = $year_current;
79 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
80 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
82 if (empty($date_start) || empty($date_end))
88 $name = $langs->trans(
"PurchasesJournal");
92 $description = $langs->trans(
"DescPurchasesJournal").
'<br>';
93 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans(
"DepositsAreNotIncluded");
94 else $description .= $langs->trans(
"DepositsAreIncluded");
95 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
97 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink);
99 $p = explode(
":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
103 $sql =
"SELECT f.rowid, f.ref_supplier, f.type, f.datef, f.libelle as label,";
104 $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,";
105 $sql .=
" s.rowid as socid, s.nom as name, s.code_compta_fournisseur,";
106 $sql .=
" p.rowid as pid, p.ref as ref, p.accountancy_code_buy,";
107 $sql .=
" ct.accountancy_code_buy as account_tva, ct.recuperableonly";
108 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as fd";
109 $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);
110 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
111 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
112 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
113 $sql .=
" WHERE f.fk_statut > 0 AND f.entity IN (".getEntity(
'invoice').
")";
114 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .=
" AND f.type IN (0,1,2)";
115 else $sql .=
" AND f.type IN (0,1,2,3)";
116 if ($date_start && $date_end) $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
119 if (in_array($db->type, array(
'mysql',
'mysqli'))) $db->query(
'SET SQL_BIG_SELECTS=1');
121 $result = $db->query($sql);
124 $num = $db->num_rows($result);
126 $cptfour = (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER !=
"") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans(
"CodeNotDef"));
127 $cpttva = (!empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
133 $tablocaltax1 = array();
134 $tablocaltax2 = array();
135 $tabcompany = array();
140 $obj = $db->fetch_object($result);
142 $compta_soc = (($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $cptfour);
143 $compta_prod = $obj->accountancy_code_buy;
144 if (empty($compta_prod))
146 if ($obj->product_type == 0) $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
147 else $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
149 $compta_tva = (!empty($obj->account_tva) ? $obj->account_tva : $cpttva);
150 $compta_localtax1 = (!empty($obj->account_localtax1) ? $obj->account_localtax1 : $langs->trans(
"CodeNotDef"));
151 $compta_localtax2 = (!empty($obj->account_localtax2) ? $obj->account_localtax2 : $langs->trans(
"CodeNotDef"));
154 $compta_localtax1 = (!empty($account_localtax1[2]) ? $account_localtax1[2] : $langs->trans(
"CodeNotDef"));
156 $compta_localtax2 = (!empty($account_localtax2[2]) ? $account_localtax2[2] : $langs->trans(
"CodeNotDef"));
158 $tabfac[$obj->rowid][
"date"] = $obj->datef;
159 $tabfac[$obj->rowid][
"ref"] = $obj->ref_supplier;
160 $tabfac[$obj->rowid][
"type"] = $obj->type;
161 $tabfac[$obj->rowid][
"lib"] = $obj->label;
162 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
163 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
164 if ($obj->recuperableonly != 1) $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
165 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
166 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
167 $tabcompany[$obj->rowid] = array(
'id'=>$obj->socid,
'name'=>$obj->name);
178 print "<table class=\"noborder\" width=\"100%\">";
179 print "<tr class=\"liste_titre\">";
181 print "<td>".$langs->trans(
"Date").
"</td>";
182 print "<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
183 print "<td>".$langs->trans(
"Account").
"</td>";
184 print "<td>".$langs->trans(
"Type").
"</td><td class='right'>".$langs->trans(
"Debit").
"</td><td class='right'>".$langs->trans(
"Credit").
"</td>";
191 foreach ($tabfac as $key => $val)
193 $invoicestatic->id = $key;
194 $invoicestatic->ref = $val[
"ref"];
195 $invoicestatic->type = $val[
"type"];
197 $companystatic->id = $tabcompany[$key][
'id'];
198 $companystatic->name = $tabcompany[$key][
'name'];
202 'var' => $tabht[$key],
203 'label' => $langs->trans(
'Products'),
206 'var' => $tabtva[$key],
207 'label' => $langs->trans(
'VAT')
210 'var' => $tablocaltax1[$key],
211 'label' => $langs->transcountry(
'LT1', $mysoc->country_code)
214 'var' => $tablocaltax2[$key],
215 'label' => $langs->transcountry(
'LT2', $mysoc->country_code)
218 'var' => $tabttc[$key],
219 'label' => $langs->trans(
'ThirdParty').
' ('.$companystatic->getNomUrl(0,
'supplier', 16).
')',
225 foreach ($lines as $line)
227 foreach ($line[
'var'] as $k => $mt)
229 if (isset($line[
'nomtcheck']) || $mt)
231 print '<tr class="oddeven">';
232 print "<td>".dol_print_date($db->jdate($val[
"date"])).
"</td>";
233 print "<td>".$invoicestatic->getNomUrl(1).
"</td>";
234 print "<td>".$k.
"</td><td>".$line[
'label'].
"</td>";
236 if (isset($line[
'inv']))
238 print '<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
239 print '<td class="right">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
241 print '<td class="right">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
242 print '<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Class to manage suppliers invoices.
Class to manage suppliers.
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...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.