27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
35 $langs->loadLangs(array(
"compta",
"bills",
"other",
"accountancy"));
37 $validatemonth =
GETPOST(
'validatemonth',
'int');
38 $validateyear =
GETPOST(
'validateyear',
'int');
44 if ($user->socid > 0) {
47 if (empty($user->rights->accounting->bind->write)) {
53 $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
55 $year_start =
GETPOST(
"year",
'int');
62 $year_end = $year_start + 1;
63 $month_end = $month_start - 1;
68 $search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
70 $year_current = $year_start;
73 $action =
GETPOST(
'action',
'aZ09');
75 $chartaccountcode =
dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS,
'accounting_system',
'rowid',
'pcg_version');
81 if ($user->socid > 0) {
84 if (empty($user->rights->accounting->mouvements->lire)) {
93 if (($action ==
'clean' || $action ==
'validatehistory') && $user->rights->accounting->bind->write) {
96 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det as fd";
97 $sql1 .=
" SET fk_code_ventilation = 0";
98 $sql1 .=
' WHERE fd.fk_code_ventilation NOT IN';
99 $sql1 .=
' (SELECT accnt.rowid ';
100 $sql1 .=
' FROM '.MAIN_DB_PREFIX.
'accounting_account as accnt';
101 $sql1 .=
' INNER JOIN '.MAIN_DB_PREFIX.
'accounting_system as syst';
102 $sql1 .=
' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid='.$conf->global->CHARTOFACCOUNTS.
' AND accnt.entity = '.$conf->entity.
')';
103 $sql1 .=
' AND fd.fk_facture_fourn IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_fourn WHERE entity = '.$conf->entity.
')';
104 $sql1 .=
' AND fk_code_ventilation <> 0';
106 dol_syslog(
"htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
107 $resql1 = $db->query($sql1);
118 if ($action ==
'validatehistory') {
142 $sql =
"SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype,";
143 $sql .=
" l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
144 $sql .=
" p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,";
145 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
146 $sql .=
" ppe.accountancy_code_buy as code_buy, ppe.accountancy_code_buy_intra as code_buy_intra, ppe.accountancy_code_buy_export as code_buy_export,";
148 $sql .=
" p.accountancy_code_buy as code_buy, p.accountancy_code_buy_intra as code_buy_intra, p.accountancy_code_buy_export as code_buy_export,";
150 $sql .=
" aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
151 $sql .=
" co.code as country_code, co.label as country_label,";
152 $sql .=
" s.tva_intra,";
153 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
154 $sql .=
" spe.accountancy_code_buy as company_code_buy";
156 $sql .=
" s.accountancy_code_buy as company_code_buy";
158 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
159 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
160 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
161 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
163 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
164 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
165 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = l.fk_product";
166 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
167 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
169 $alias_societe_perentity = empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED) ?
"s" :
"spe";
170 $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ?
"p" :
"ppe";
171 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON " . $alias_product_perentity .
".accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa.entity = ".$conf->entity;
172 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa2 ON " . $alias_product_perentity .
".accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa2.entity = ".$conf->entity;
173 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa3 ON " . $alias_product_perentity .
".accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa3.entity = ".$conf->entity;
174 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa4 ON " . $alias_product_perentity .
".accountancy_code_buy = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa4.entity = ".$conf->entity;
175 $sql .=
" WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
176 $sql .=
" AND l.product_type <= 2";
177 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn', 0).
")";
178 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
179 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
181 if ($validatemonth && $validateyear) {
185 dol_syslog(
'htdocs/accountancy/supplier/index.php');
187 $result = $db->query($sql);
192 $num_lines = $db->num_rows($result);
194 $isBuyerInEEC =
isInEEC($mysoc);
196 $thirdpartystatic =
new Societe($db);
199 $product_static =
new Product($db);
202 while ($i < min($num_lines, 10000)) {
203 $objp = $db->fetch_object($result);
205 $thirdpartystatic->id = $objp->socid;
206 $thirdpartystatic->name = $objp->name;
207 $thirdpartystatic->client = $objp->client;
208 $thirdpartystatic->fournisseur = $objp->fournisseur;
209 $thirdpartystatic->code_client = $objp->code_client;
210 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
211 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
212 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
213 $thirdpartystatic->email = $objp->email;
214 $thirdpartystatic->country_code = $objp->country_code;
215 $thirdpartystatic->tva_intra = $objp->tva_intra;
216 $thirdpartystatic->code_compta_product = $objp->company_code_buy;
218 $product_static->ref = $objp->product_ref;
219 $product_static->id = $objp->product_id;
220 $product_static->type = $objp->type;
221 $product_static->label = $objp->product_label;
222 $product_static->status = $objp->status;
223 $product_static->status_buy = $objp->status_buy;
224 $product_static->accountancy_code_sell = $objp->code_sell;
225 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
226 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
227 $product_static->accountancy_code_buy = $objp->code_buy;
228 $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
229 $product_static->accountancy_code_buy_export = $objp->code_buy_export;
230 $product_static->tva_tx = $objp->tva_tx_prod;
232 $facture_static->ref = $objp->ref;
233 $facture_static->id = $objp->facid;
234 $facture_static->type = $objp->ftype;
235 $facture_static->date = $objp->datef;
237 $facture_static_det->id = $objp->rowid;
238 $facture_static_det->total_ht = $objp->total_ht;
239 $facture_static_det->tva_tx = $objp->tva_tx_line;
240 $facture_static_det->vat_src_code = $objp->vat_src_code;
241 $facture_static_det->product_type = $objp->type_l;
242 $facture_static_det->desc = $objp->description;
244 $accountingAccountArray = array(
245 'dom'=>$objp->aarowid,
246 'intra'=>$objp->aarowid_intra,
247 'export'=>$objp->aarowid_export,
248 'thirdparty' =>$objp->aarowid_thirdparty);
250 $code_buy_p_notset =
'';
251 $code_buy_t_notset =
'';
255 $return = $accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facture_static, $facture_static_det, $accountingAccountArray,
'supplier');
256 if (!is_array($return) && $return<0) {
259 $suggestedid = $return[
'suggestedid'];
260 $suggestedaccountingaccountfor = $return[
'suggestedaccountingaccountfor'];
262 if (!empty($suggestedid) && $suggestedaccountingaccountfor !=
'' && $suggestedaccountingaccountfor !=
'eecwithoutvatnumber') {
263 $suggestedid = $return[
'suggestedid'];
269 if ($suggestedid > 0) {
270 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det";
271 $sqlupdate .=
" SET fk_code_ventilation = ".((int) $suggestedid);
272 $sqlupdate .=
" WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id);
274 $resqlupdate = $db->query($sqlupdate);
288 if ($num_lines > 10000) {
289 $notpossible += ($num_lines - 10000);
297 setEventMessages($langs->trans(
'AutomaticBindingDone', $nbbinddone, $notpossible),
null,
'mesgs');
306 llxHeader(
'', $langs->trans(
"SuppliersVentilation"));
308 $textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current - 1).
'">'.
img_previous().
'</a>';
309 $textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current + 1).
'">'.
img_next().
'</a>';
311 print
load_fiche_titre($langs->trans(
"SuppliersVentilation").
" ".$textprevyear.
" ".$langs->trans(
"Year").
" ".$year_start.
" ".$textnextyear,
'',
'title_accountancy');
313 print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilSupplier").
'</span><br>';
314 print
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"DescVentilMore", $langs->transnoentitiesnoconv(
"ValidateHistory"), $langs->transnoentitiesnoconv(
"ToBind")).
'<br>';
319 $buttonbind =
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=validatehistory&token='.
newToken().
'">'.$langs->trans(
"ValidateHistory").
'</a>';
322 print_barre_liste(
img_picto(
'',
'unlink',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesNotBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonbind,
'', 0, 1, 1);
325 print
'<div class="div-table-responsive-no-min">';
326 print
'<table class="noborder centpercent">';
327 print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
328 print
'<td>'.$langs->trans(
"Label").
'</td>';
329 for ($i = 1; $i <= 12; $i++) {
330 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
335 if ($cursormonth > 12) {
338 $cursoryear = ($cursormonth < ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1)) ? $y + 1 : $y;
341 print
'<td width="60" class="right">';
342 if (!empty($tmp[
'mday'])) {
343 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
344 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
345 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/supplier/list.php?'.$param.
'">';
347 print $langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT));
348 if (!empty($tmp[
'mday'])) {
353 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
355 $sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
356 $sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
357 for ($i = 1; $i <= 12; $i++) {
358 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
362 $sql .=
" SUM(".$db->ifsql(
"MONTH(ff.datef)=".$j,
"ffd.total_ht",
"0").
") AS month".str_pad($j, 2,
"0", STR_PAD_LEFT).
",";
364 $sql .=
" SUM(ffd.total_ht) as total";
365 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
366 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
367 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
368 $sql .=
" WHERE ff.datef >= '".$db->idate($search_date_start).
"'";
369 $sql .=
" AND ff.datef <= '".$db->idate($search_date_end).
"'";
371 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
372 $sql .=
" AND ff.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
374 $sql .=
" AND ff.fk_statut > 0";
375 $sql .=
" AND ffd.product_type <= 2";
376 $sql .=
" AND ff.entity IN (".getEntity(
'facture_fourn', 0).
")";
377 $sql .=
" AND aa.account_number IS NULL";
378 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
383 $sql .=
" GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
385 dol_syslog(
'htdocs/accountancy/supplier/index.php', LOG_DEBUG);
386 $resql = $db->query($sql);
388 $num = $db->num_rows(
$resql);
390 while ($row = $db->fetch_row(
$resql)) {
391 print
'<tr class="oddeven">';
393 if ($row[0] ==
'tobind') {
394 print
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>';
400 if ($row[0] ==
'tobind') {
401 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/supplier/list.php?search_year='.((
int) $y), $langs->transnoentitiesnoconv(
"ToBind"));
406 for ($i = 2; $i <= 13; $i++) {
407 print
'<td class="right nowraponall amount">';
408 print
price($row[$i]);
411 print
'<td class="right nowraponall amount"><b>'.price($row[14]).
'</b></td>';
417 print
'<tr class="oddeven"><td colspan="16">';
418 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
422 print $db->lasterror();
431 print_barre_liste(
img_picto(
'',
'link',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
434 print
'<div class="div-table-responsive-no-min">';
435 print
'<table class="noborder centpercent">';
436 print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
437 print
'<td>'.$langs->trans(
"Label").
'</td>';
438 for ($i = 1; $i <= 12; $i++) {
439 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
444 if ($cursormonth > 12) {
447 $cursoryear = ($cursormonth < ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1)) ? $y + 1 : $y;
450 print
'<td width="60" class="right">';
451 if (!empty($tmp[
'mday'])) {
452 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
453 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
454 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/supplier/lines.php?'.$param.
'">';
456 print $langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT));
457 if (!empty($tmp[
'mday'])) {
462 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
464 $sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
465 $sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
466 for ($i = 1; $i <= 12; $i++) {
467 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
471 $sql .=
" SUM(".$db->ifsql(
"MONTH(ff.datef)=".$j,
"ffd.total_ht",
"0").
") AS month".str_pad($j, 2,
"0", STR_PAD_LEFT).
",";
473 $sql .=
" SUM(ffd.total_ht) as total";
474 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
475 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
476 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
477 $sql .=
" WHERE ff.datef >= '".$db->idate($search_date_start).
"'";
478 $sql .=
" AND ff.datef <= '".$db->idate($search_date_end).
"'";
480 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
481 $sql .=
" AND ff.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
483 $sql .=
" AND ff.entity IN (".getEntity(
'facture_fourn', 0).
")";
484 $sql .=
" AND ff.fk_statut > 0";
485 $sql .=
" AND ffd.product_type <= 2";
486 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
491 $sql .=
" AND aa.account_number IS NOT NULL";
492 $sql .=
" GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
493 $sql .=
' ORDER BY aa.account_number';
495 dol_syslog(
'htdocs/accountancy/supplier/index.php');
496 $resql = $db->query($sql);
498 $num = $db->num_rows(
$resql);
500 while ($row = $db->fetch_row(
$resql)) {
501 print
'<tr class="oddeven">';
503 if ($row[0] ==
'tobind') {
504 print $langs->trans(
"Unknown");
510 print
'<td class="left">';
511 if ($row[0] ==
'tobind') {
512 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/supplier/list.php?search_year='.((
int) $y), $langs->transnoentitiesnoconv(
"ToBind"));
518 for ($i = 2; $i <= 13; $i++) {
519 print
'<td class="right nowraponall amount">';
520 print
price($row[$i]);
523 print
'<td class="right nowraponall amount"><b>'.price($row[14]).
'</b></td>';
529 print
'<tr class="oddeven"><td colspan="16">';
530 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
534 print $db->lasterror();
540 if ($conf->global->MAIN_FEATURES_LEVEL > 0) {
544 print_barre_liste($langs->trans(
"OtherInfo"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
547 print
'<div class="div-table-responsive-no-min">';
548 print
'<table class="noborder centpercent">';
549 print
'<tr class="liste_titre"><td>'.$langs->trans(
"Total").
'</td>';
550 for ($i = 1; $i <= 12; $i++) {
551 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
555 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
557 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
559 $sql =
"SELECT '".$db->escape($langs->trans(
"CAHTF")).
"' AS label,";
560 for ($i = 1; $i <= 12; $i++) {
561 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
565 $sql .=
" SUM(".$db->ifsql(
"MONTH(ff.datef)=".$j,
"ffd.total_ht",
"0").
") AS month".str_pad($j, 2,
"0", STR_PAD_LEFT).
",";
567 $sql .=
" SUM(ffd.total_ht) as total";
568 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
569 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
570 $sql .=
" WHERE ff.datef >= '".$db->idate($search_date_start).
"'";
571 $sql .=
" AND ff.datef <= '".$db->idate($search_date_end).
"'";
573 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
574 $sql .=
" AND ff.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
576 $sql .=
" AND ff.entity IN (".getEntity(
'facture_fourn', 0).
")";
577 $sql .=
" AND ff.fk_statut > 0";
578 $sql .=
" AND ffd.product_type <= 2";
579 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
585 dol_syslog(
'htdocs/accountancy/supplier/index.php');
586 $resql = $db->query($sql);
588 $num = $db->num_rows(
$resql);
590 while ($row = $db->fetch_row(
$resql)) {
591 print
'<tr><td>'.$row[0].
'</td>';
592 for ($i = 1; $i <= 12; $i++) {
593 print
'<td class="right nowraponall amount">'.price($row[$i]).
'</td>';
595 print
'<td class="right nowraponall amount"><b>'.price($row[13]).
'</b></td>';
600 print $db->lasterror();