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';
34 $langs->loadLangs(array(
"compta",
"bills",
"other",
"main",
"accountancy"));
37 if (empty($conf->accounting->enabled)) {
42 if (!$user->rights->accounting->bind->write)
46 $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
52 $year_end = $year_start + 1;
53 $month_end = $month_start - 1;
59 $search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
61 $year_current = $year_start;
64 $action =
GETPOST(
'action',
'aZ09');
66 $chartaccountcode =
dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS,
'accounting_system',
'rowid',
'pcg_version');
73 if ($action ==
'clean' || $action ==
'validatehistory')
77 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det as fd";
78 $sql1 .=
" SET fk_code_ventilation = 0";
79 $sql1 .=
' WHERE fd.fk_code_ventilation NOT IN';
80 $sql1 .=
' (SELECT accnt.rowid ';
81 $sql1 .=
' FROM '.MAIN_DB_PREFIX.
'accounting_account as accnt';
82 $sql1 .=
' INNER JOIN '.MAIN_DB_PREFIX.
'accounting_system as syst';
83 $sql1 .=
' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid='.$conf->global->CHARTOFACCOUNTS.
' AND accnt.entity = '.$conf->entity.
')';
84 $sql1 .=
' AND fd.fk_facture_fourn IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_fourn WHERE entity = '.$conf->entity.
')';
85 $sql1 .=
' AND fk_code_ventilation <> 0';
86 dol_syslog(
"htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
87 $resql1 = $db->query($sql1);
98 if ($action ==
'validatehistory') {
119 $sql =
"SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype,";
120 $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,";
121 $sql .=
" p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type,";
122 $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, p.tva_tx as tva_tx_prod,";
123 $sql .=
" aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export,";
124 $sql .=
" co.code as country_code, co.label as country_label,";
125 $sql .=
" s.tva_intra";
126 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
127 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
128 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
129 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
130 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = l.fk_product";
131 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa.entity = ".$conf->entity;
132 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa2 ON p.accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa2.entity = ".$conf->entity;
133 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa3 ON p.accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa3.entity = ".$conf->entity;
134 $sql .=
" WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
135 $sql .=
" AND l.product_type <= 2";
137 dol_syslog(
'htdocs/accountancy/supplier/index.php');
139 $result = $db->query($sql);
144 $num_lines = $db->num_rows($result);
146 $isBuyerInEEC =
isInEEC($mysoc);
149 while ($i < min($num_lines, 10000)) {
150 $objp = $db->fetch_object($result);
152 $isSellerInEEC =
isInEEC($objp);
155 $suggestedaccountingaccountfor =
'';
156 if (($objp->country_code == $mysoc->country_code) || empty($objp->country_code)) {
157 $objp->code_buy_p = $objp->code_buy;
158 $objp->aarowid_suggest = $objp->aarowid;
159 $suggestedaccountingaccountfor =
'';
161 if ($isSellerInEEC && $isBuyerInEEC) {
162 $objp->code_buy_p = $objp->code_buy_intra;
163 $objp->aarowid_suggest = $objp->aarowid_intra;
164 $suggestedaccountingaccountfor =
'eec';
166 $objp->code_buy_p = $objp->code_buy_export;
167 $objp->aarowid_suggest = $objp->aarowid_export;
168 $suggestedaccountingaccountfor =
'export';
172 if ($objp->aarowid_suggest > 0)
174 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.
"facture_fourn_det";
175 $sqlupdate .=
" SET fk_code_ventilation = ".$objp->aarowid_suggest;
176 $sqlupdate .=
" WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".$objp->rowid;
178 $resqlupdate = $db->query($sqlupdate);
205 llxHeader(
'', $langs->trans(
"SuppliersVentilation"));
207 $textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current - 1).
'">'.
img_previous().
'</a>';
208 $textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current + 1).
'">'.
img_next().
'</a>';
210 print load_fiche_titre($langs->trans(
"SuppliersVentilation").
" ".$textprevyear.
" ".$langs->trans(
"Year").
" ".$year_start.
" ".$textnextyear,
'',
'title_accountancy');
212 print '<span class="opacitymedium">'.$langs->trans(
"DescVentilSupplier").
'</span><br>';
213 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"DescVentilMore", $langs->transnoentitiesnoconv(
"ValidateHistory"), $langs->transnoentitiesnoconv(
"ToBind")).
'<br>';
218 $buttonbind =
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?year='.$year_current.
'&action=validatehistory">'.$langs->trans(
"ValidateHistory").
'</a>';
221 print_barre_liste($langs->trans(
"OverviewOfAmountOfLinesNotBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonbind,
'', 0, 1, 1);
224 print '<div class="div-table-responsive-no-min">';
225 print
'<table class="noborder centpercent">';
226 print
'<tr class="liste_titre"><td width="200">'.$langs->trans(
"Account").
'</td>';
227 print
'<td width="200" class="left">'.$langs->trans(
"Label").
'</td>';
228 for ($i = 1; $i <= 12; $i++) {
229 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
230 if ($j > 12) $j -= 12;
231 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
233 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
235 $sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
236 $sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
237 for ($i = 1; $i <= 12; $i++) {
238 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
239 if ($j > 12) $j -= 12;
240 $sql .=
" SUM(".$db->ifsql(
'MONTH(ff.datef)='.$j,
'ffd.total_ht',
'0').
") AS month".str_pad($j, 2,
'0', STR_PAD_LEFT).
",";
242 $sql .=
" SUM(ffd.total_ht) as total";
243 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
244 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
245 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
246 $sql .=
" WHERE ff.datef >= '".$db->idate($search_date_start).
"'";
247 $sql .=
" AND ff.datef <= '".$db->idate($search_date_end).
"'";
249 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
250 $sql .=
" AND ff.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
252 $sql .=
" AND ff.fk_statut > 0";
253 $sql .=
" AND ffd.product_type <= 2";
254 $sql .=
" AND ff.entity IN (".getEntity(
'facture_fourn', 0).
")";
255 $sql .=
" AND aa.account_number IS NULL";
256 $sql .=
" GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
258 dol_syslog(
'htdocs/accountancy/supplier/index.php');
259 $resql = $db->query($sql);
261 $num = $db->num_rows(
$resql);
263 while ($row = $db->fetch_row(
$resql)) {
264 print
'<tr class="oddeven"><td>';
265 if ($row[0] ==
'tobind')
267 print $langs->trans(
"Unknown");
270 print
'<td class="left">';
271 if ($row[0] ==
'tobind')
273 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/supplier/list.php?search_year='.$y, $langs->transnoentitiesnoconv(
"ToBind"));
274 }
else print $row[1];
276 for ($i = 2; $i <= 12; $i++) {
277 print
'<td class="nowrap right">'.price($row[$i]).
'</td>';
279 print
'<td class="nowrap right">'.price($row[13]).
'</td>';
280 print
'<td class="nowrap right"><b>'.price($row[14]).
'</b></td>';
285 print $db->lasterror();
294 print_barre_liste($langs->trans(
"OverviewOfAmountOfLinesBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
297 print
'<div class="div-table-responsive-no-min">';
298 print
'<table class="noborder centpercent">';
299 print
'<tr class="liste_titre"><td width="200">'.$langs->trans(
"Account").
'</td>';
300 print
'<td width="200" class="left">'.$langs->trans(
"Label").
'</td>';
301 for ($i = 1; $i <= 12; $i++) {
302 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
303 if ($j > 12) $j -= 12;
304 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
306 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
308 $sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
309 $sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
310 for ($i = 1; $i <= 12; $i++) {
311 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
312 if ($j > 12) $j -= 12;
313 $sql .=
" SUM(".$db->ifsql(
'MONTH(ff.datef)='.$j,
'ffd.total_ht',
'0').
") AS month".str_pad($j, 2,
'0', STR_PAD_LEFT).
",";
315 $sql .=
" SUM(ffd.total_ht) as total";
316 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
317 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
318 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
319 $sql .=
" WHERE ff.datef >= '".$db->idate($search_date_start).
"'";
320 $sql .=
" AND ff.datef <= '".$db->idate($search_date_end).
"'";
322 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
323 $sql .=
" AND ff.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
325 $sql .=
" AND ff.fk_statut > 0";
326 $sql .=
" AND ffd.product_type <= 2";
327 $sql .=
" AND ff.entity IN (".getEntity(
'facture_fourn', 0).
")";
328 $sql .=
" AND aa.account_number IS NOT NULL";
329 $sql .=
" GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
331 dol_syslog(
'htdocs/accountancy/supplier/index.php');
332 $resql = $db->query($sql);
334 $num = $db->num_rows(
$resql);
336 while ($row = $db->fetch_row(
$resql)) {
337 print
'<tr class="oddeven"><td>';
338 if ($row[0] ==
'tobind')
340 print $langs->trans(
"Unknown");
343 print
'<td class="left">';
344 if ($row[0] ==
'tobind')
346 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/supplier/list.php?search_year='.$y, $langs->transnoentitiesnoconv(
"ToBind"));
347 }
else print $row[1];
349 for ($i = 2; $i <= 12; $i++) {
350 print
'<td class="nowrap right">'.price($row[$i]).
'</td>';
352 print
'<td class="nowrap right">'.price($row[13]).
'</td>';
353 print
'<td class="nowrap right"><b>'.price($row[14]).
'</b></td>';
358 print $db->lasterror();
365 if ($conf->global->MAIN_FEATURES_LEVEL > 0)
370 print_barre_liste($langs->trans(
"OtherInfo"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
373 print
'<div class="div-table-responsive-no-min">';
374 print
'<table class="noborder centpercent">';
375 print
'<tr class="liste_titre"><td width="400" class="left">'.$langs->trans(
"Total").
'</td>';
376 for ($i = 1; $i <= 12; $i++) {
377 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
378 if ($j > 12) $j -= 12;
379 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
381 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
383 $sql =
"SELECT '".$db->escape($langs->trans(
"CAHTF")).
"' AS label,";
384 for ($i = 1; $i <= 12; $i++) {
385 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
386 if ($j > 12) $j -= 12;
387 $sql .=
" SUM(".$db->ifsql(
'MONTH(ff.datef)='.$j,
'ffd.total_ht',
'0').
") AS month".str_pad($j, 2,
'0', STR_PAD_LEFT).
",";
389 $sql .=
" SUM(ffd.total_ht) as total";
390 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
391 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
392 $sql .=
" WHERE ff.datef >= '".$db->idate($search_date_start).
"'";
393 $sql .=
" AND ff.datef <= '".$db->idate($search_date_end).
"'";
395 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
396 $sql .=
" AND ff.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
398 $sql .=
" AND ff.fk_statut > 0";
399 $sql .=
" AND ffd.product_type <= 2";
400 $sql .=
" AND ff.entity IN (".getEntity(
'facture_fourn', 0).
")";
402 dol_syslog(
'htdocs/accountancy/supplier/index.php');
403 $resql = $db->query($sql);
405 $num = $db->num_rows(
$resql);
407 while ($row = $db->fetch_row(
$resql)) {
408 print
'<tr><td>'.$row[0].
'</td>';
409 for ($i = 1; $i <= 12; $i++) {
410 print
'<td class="nowrap right">'.price($row[$i]).
'</td>';
412 print
'<td class="nowrap right"><b>'.price($row[13]).
'</b></td>';
417 print $db->lasterror();
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.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
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_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)