30 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
38 $langs->loadLangs(array(
"compta",
"bills",
"other",
"accountancy"));
40 $validatemonth =
GETPOST(
'validatemonth',
'int');
41 $validateyear =
GETPOST(
'validateyear',
'int');
47 if ($user->socid > 0) {
50 if (!$user->hasRight(
'accounting',
'bind',
'write')) {
56 $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
58 $year_start =
GETPOST(
"year",
'int');
65 $year_end = $year_start + 1;
66 $month_end = $month_start - 1;
71 $search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
73 $year_current = $year_start;
76 $action =
GETPOST(
'action',
'aZ09');
78 $chartaccountcode =
dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS,
'accounting_system',
'rowid',
'pcg_version');
84 if ($user->socid > 0) {
87 if (!$user->hasRight(
'accounting',
'mouvements',
'lire')) {
96 if (($action ==
'clean' || $action ==
'validatehistory') && $user->hasRight(
'accounting',
'bind',
'write')) {
99 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet as fd";
100 $sql1 .=
" SET fk_code_ventilation = 0";
101 $sql1 .=
' WHERE fd.fk_code_ventilation NOT IN';
102 $sql1 .=
' (SELECT accnt.rowid ';
103 $sql1 .=
' FROM '.MAIN_DB_PREFIX.
'accounting_account as accnt';
104 $sql1 .=
' INNER JOIN '.MAIN_DB_PREFIX.
'accounting_system as syst';
105 $sql1 .=
' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid='.((int) $conf->global->CHARTOFACCOUNTS).
' AND accnt.entity = '.((int) $conf->entity).
')';
106 $sql1 .=
' AND fd.fk_facture IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture WHERE entity = '.((int) $conf->entity).
')';
107 $sql1 .=
' AND fk_code_ventilation <> 0';
109 dol_syslog(
"htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
110 $resql1 = $db->query($sql1);
121 if ($action ==
'validatehistory') {
145 $sql =
"SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype, f.fk_facture_source,";
146 $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,";
147 $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,";
148 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
149 $sql .=
" ppe.accountancy_code_sell as code_sell, ppe.accountancy_code_sell_intra as code_sell_intra, ppe.accountancy_code_sell_export as code_sell_export,";
151 $sql .=
" p.accountancy_code_sell as code_sell, p.accountancy_code_sell_intra as code_sell_intra, p.accountancy_code_sell_export as code_sell_export,";
153 $sql .=
" aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
154 $sql .=
" co.code as country_code, co.label as country_label,";
155 $sql .=
" s.tva_intra,";
156 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
157 $sql .=
" spe.accountancy_code_sell as company_code_sell";
159 $sql .=
" s.accountancy_code_sell as company_code_sell";
161 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
162 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
163 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
164 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
166 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
167 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facturedet as l ON f.rowid = l.fk_facture";
168 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = l.fk_product";
169 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
170 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
172 $alias_societe_perentity = empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED) ?
"s" :
"spe";
173 $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ?
"p" :
"ppe";
174 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON " . $alias_product_perentity .
".accountancy_code_sell = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa.entity = ".$conf->entity;
175 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa2 ON " . $alias_product_perentity .
".accountancy_code_sell_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa2.entity = ".$conf->entity;
176 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa3 ON " . $alias_product_perentity .
".accountancy_code_sell_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa3.entity = ".$conf->entity;
177 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa4 ON " . $alias_societe_perentity .
".accountancy_code_sell = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa4.entity = ".$conf->entity;
178 $sql .=
" WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
179 $sql .=
" AND l.product_type <= 2";
180 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
181 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
182 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
184 if ($validatemonth && $validateyear) {
188 dol_syslog(
'htdocs/accountancy/customer/index.php');
190 $result = $db->query($sql);
195 $num_lines = $db->num_rows($result);
197 $facture_static =
new Facture($db);
199 $isSellerInEEC =
isInEEC($mysoc);
201 $thirdpartystatic =
new Societe($db);
202 $facture_static =
new Facture($db);
204 $product_static =
new Product($db);
207 while ($i < min($num_lines, 10000)) {
208 $objp = $db->fetch_object($result);
210 $thirdpartystatic->id = !empty($objp->socid) ? $objp->socid : 0;
211 $thirdpartystatic->name = !empty($objp->name) ? $objp->name :
"";
212 $thirdpartystatic->client = !empty($objp->client) ? $objp->client :
"";
213 $thirdpartystatic->fournisseur = !empty($objp->fournisseur) ? $objp->fournisseur :
"";
214 $thirdpartystatic->code_client = !empty($objp->code_client) ? $objp->code_client :
"";
215 $thirdpartystatic->code_compta_client = !empty($objp->code_compta_client) ? $objp->code_compta_client :
"";
216 $thirdpartystatic->code_fournisseur = !empty($objp->code_fournisseur) ? $objp->code_fournisseur :
"";
217 $thirdpartystatic->code_compta_fournisseur = !empty($objp->code_compta_fournisseur) ? $objp->code_compta_fournisseur :
"";
218 $thirdpartystatic->email = !empty($objp->email) ? $objp->email :
"";
219 $thirdpartystatic->country_code = !empty($objp->country_code) ? $objp->country_code :
"";
220 $thirdpartystatic->tva_intra = !empty($objp->tva_intra) ? $objp->tva_intra :
"";
221 $thirdpartystatic->code_compta_product = !empty($objp->company_code_sell) ? $objp->company_code_sell :
"";
223 $product_static->ref = $objp->product_ref;
224 $product_static->id = $objp->product_id;
225 $product_static->type = $objp->type;
226 $product_static->label = $objp->product_label;
227 $product_static->status = !empty($objp->status) ? $objp->status : 0;
228 $product_static->status_buy = !empty($objp->status_buy) ? $objp->status_buy : 0;
229 $product_static->accountancy_code_sell = $objp->code_sell;
230 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
231 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
232 $product_static->accountancy_code_buy = !empty($objp->code_buy) ? $objp->code_buy :
"";
233 $product_static->accountancy_code_buy_intra = !empty($objp->code_buy_intra) ? $objp->code_buy_intra :
"";
234 $product_static->accountancy_code_buy_export = !empty($objp->code_buy_export) ? $objp->code_buy_export :
"";
235 $product_static->tva_tx = $objp->tva_tx_prod;
237 $facture_static->ref = $objp->ref;
238 $facture_static->id = $objp->facid;
239 $facture_static->type = $objp->ftype;
240 $facture_static->date = $db->jdate($objp->datef);
241 $facture_static->fk_facture_source = $objp->fk_facture_source;
243 $facture_static_det->id = $objp->rowid;
244 $facture_static_det->total_ht = $objp->total_ht;
245 $facture_static_det->tva_tx = $objp->tva_tx_line;
246 $facture_static_det->vat_src_code = $objp->vat_src_code;
247 $facture_static_det->product_type = $objp->type_l;
248 $facture_static_det->desc = $objp->description;
250 $accountingAccountArray = array(
251 'dom'=>$objp->aarowid,
252 'intra'=>$objp->aarowid_intra,
253 'export'=>$objp->aarowid_export,
254 'thirdparty' =>$objp->aarowid_thirdparty);
256 $code_sell_p_notset =
'';
257 $code_sell_t_notset =
'';
261 $return=$accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray,
'customer');
262 if (!is_array($return) && $return < 0) {
265 $suggestedid = $return[
'suggestedid'];
266 $suggestedaccountingaccountfor = $return[
'suggestedaccountingaccountfor'];
268 if (!empty($suggestedid) && $suggestedaccountingaccountfor !=
'' && $suggestedaccountingaccountfor !=
'eecwithoutvatnumber') {
269 $suggestedid = $return[
'suggestedid'];
275 if ($suggestedid > 0) {
276 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet";
277 $sqlupdate .=
" SET fk_code_ventilation = ".((int) $suggestedid);
278 $sqlupdate .=
" WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id);
280 $resqlupdate = $db->query($sqlupdate);
294 if ($num_lines > 10000) {
295 $notpossible += ($num_lines - 10000);
303 setEventMessages($langs->trans(
'AutomaticBindingDone', $nbbinddone, $notpossible),
null,
'mesgs');
312 llxHeader(
'', $langs->trans(
"CustomersVentilation"));
314 $textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current - 1).
'">'.
img_previous().
'</a>';
315 $textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current + 1).
'">'.
img_next().
'</a>';
318 print
load_fiche_titre($langs->trans(
"CustomersVentilation").
" ".$textprevyear.
" ".$langs->trans(
"Year").
" ".$year_start.
" ".$textnextyear,
'',
'title_accountancy');
320 print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilCustomer").
'</span><br>';
321 print
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"DescVentilMore", $langs->transnoentitiesnoconv(
"ValidateHistory"), $langs->transnoentitiesnoconv(
"ToBind")).
'<br>';
327 $buttonbind =
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=validatehistory&token='.
newToken().
'">'.$langs->trans(
"ValidateHistory").
'</a>';
329 print_barre_liste(
img_picto(
'',
'unlink',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesNotBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonbind,
'', 0, 1, 1);
332 print
'<div class="div-table-responsive-no-min">';
333 print
'<table class="noborder centpercent">';
334 print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
335 print
'<td>'.$langs->trans(
"Label").
'</td>';
336 for ($i = 1; $i <= 12; $i++) {
337 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
342 if ($cursormonth > 12) {
345 $cursoryear = ($cursormonth < ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1)) ? $y + 1 : $y;
348 print
'<td width="60" class="right">';
349 if (!empty($tmp[
'mday'])) {
350 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
351 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
352 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/customer/list.php?'.$param.
'">';
354 print $langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT));
355 if (!empty($tmp[
'mday'])) {
360 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
362 $sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
363 $sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
364 for ($i = 1; $i <= 12; $i++) {
365 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
369 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef)=".$j,
"fd.total_ht",
"0").
") AS month".str_pad($j, 2,
"0", STR_PAD_LEFT).
",";
371 $sql .=
" SUM(fd.total_ht) as total";
372 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
373 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
374 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
375 $sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
376 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
378 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
379 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
381 $sql .=
" AND f.fk_statut > 0";
382 $sql .=
" AND fd.product_type <= 2";
383 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
384 $sql .=
" AND aa.account_number IS NULL";
385 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
390 $sql .=
" GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label";
392 dol_syslog(
'htdocs/accountancy/customer/index.php', LOG_DEBUG);
393 $resql = $db->query($sql);
395 $num = $db->num_rows(
$resql);
397 while ($row = $db->fetch_row(
$resql)) {
398 print
'<tr class="oddeven">';
400 if ($row[0] ==
'tobind') {
401 print
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>';
407 if ($row[0] ==
'tobind') {
408 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/customer/list.php?search_year='.((
int) $y), $langs->transnoentitiesnoconv(
"ToBind"));
413 for ($i = 2; $i <= 13; $i++) {
414 $cursormonth = (($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) + $i - 2);
415 if ($cursormonth > 12) {
418 $cursoryear = ($cursormonth < ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1)) ? $y + 1 : $y;
421 print
'<td class="right nowraponall amount">';
422 print
price($row[$i]);
425 print
'<td class="right nowraponall amount"><b>'.price($row[14]).
'</b></td>';
431 print
'<tr class="oddeven"><td colspan="16">';
432 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
436 print $db->lasterror();
445 print_barre_liste(
img_picto(
'',
'link',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
448 print
'<div class="div-table-responsive-no-min">';
449 print
'<table class="noborder centpercent">';
450 print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
451 print
'<td>'.$langs->trans(
"Label").
'</td>';
452 for ($i = 1; $i <= 12; $i++) {
453 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
458 if ($cursormonth > 12) {
461 $cursoryear = ($cursormonth < ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1)) ? $y + 1 : $y;
464 print
'<td width="60" class="right">';
465 if (!empty($tmp[
'mday'])) {
466 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
467 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
468 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/customer/lines.php?'.$param.
'">';
470 print $langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT));
471 if (!empty($tmp[
'mday'])) {
476 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
478 $sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
479 $sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
480 for ($i = 1; $i <= 12; $i++) {
481 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
485 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef)=".$j,
"fd.total_ht",
"0").
") AS month".str_pad($j, 2,
"0", STR_PAD_LEFT).
",";
487 $sql .=
" SUM(fd.total_ht) as total";
488 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
489 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
490 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
491 $sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
492 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
494 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
495 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
497 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
498 $sql .=
" AND f.fk_statut > 0";
499 $sql .=
" AND fd.product_type <= 2";
500 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
505 $sql .=
" AND aa.account_number IS NOT NULL";
506 $sql .=
" GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label";
507 $sql .=
' ORDER BY aa.account_number';
509 dol_syslog(
'htdocs/accountancy/customer/index.php');
510 $resql = $db->query($sql);
512 $num = $db->num_rows(
$resql);
514 while ($row = $db->fetch_row(
$resql)) {
515 print
'<tr class="oddeven">';
517 if ($row[0] ==
'tobind') {
518 print $langs->trans(
"Unknown");
525 if ($row[0] ==
'tobind') {
526 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/customer/list.php?search_year='.((
int) $y), $langs->transnoentitiesnoconv(
"ToBind"));
532 for ($i = 2; $i <= 13; $i++) {
533 $cursormonth = (($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) + $i - 2);
534 if ($cursormonth > 12) {
537 $cursoryear = ($cursormonth < ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1)) ? $y + 1 : $y;
540 print
'<td class="right nowraponall amount">';
541 print
price($row[$i]);
544 print
'<td class="right nowraponall amount"><b>'.price($row[14]).
'</b></td>';
550 print
'<tr class="oddeven"><td colspan="16">';
551 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
555 print $db->lasterror();
561 if ($conf->global->MAIN_FEATURES_LEVEL > 0) {
565 print_barre_liste($langs->trans(
"OtherInfo"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
568 print
'<div class="div-table-responsive-no-min">';
569 print
'<table class="noborder centpercent">';
570 print
'<tr class="liste_titre"><td lass="left">'.$langs->trans(
"TotalVente").
'</td>';
571 for ($i = 1; $i <= 12; $i++) {
572 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
576 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
578 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
580 $sql =
"SELECT '".$db->escape($langs->trans(
"TotalVente")).
"' AS total,";
581 for ($i = 1; $i <= 12; $i++) {
582 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
586 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef)=".$j,
"fd.total_ht",
"0").
") AS month".str_pad($j, 2,
"0", STR_PAD_LEFT).
",";
588 $sql .=
" SUM(fd.total_ht) as total";
589 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
590 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
591 $sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
592 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
594 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
595 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
597 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
598 $sql .=
" AND f.fk_statut > 0";
599 $sql .=
" AND fd.product_type <= 2";
600 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
606 dol_syslog(
'htdocs/accountancy/customer/index.php');
607 $resql = $db->query($sql);
609 $num = $db->num_rows(
$resql);
611 while ($row = $db->fetch_row(
$resql)) {
612 print
'<tr><td>'.$row[0].
'</td>';
613 for ($i = 1; $i <= 12; $i++) {
614 print
'<td class="right nowraponall amount">'.price($row[$i]).
'</td>';
616 print
'<td class="right nowraponall amount"><b>'.price($row[13]).
'</b></td>';
621 print $db->lasterror();
629 print
'<div class="div-table-responsive-no-min">';
630 print
'<table class="noborder centpercent">';
631 print
'<tr class="liste_titre"><td>'.$langs->trans(
"TotalMarge").
'</td>';
632 for ($i = 1; $i <= 12; $i++) {
633 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
637 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
639 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
640 $sql =
"SELECT '".$db->escape($langs->trans(
"Vide")).
"' AS marge,";
641 for ($i = 1; $i <= 12; $i++) {
642 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
646 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef)=".$j,
647 " (".$db->ifsql(
"fd.total_ht < 0",
648 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))",
649 " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").
")",
650 0).
") AS month".str_pad($j, 2,
'0', STR_PAD_LEFT).
",";
652 $sql .=
" SUM(".$db->ifsql(
"fd.total_ht < 0",
653 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))",
654 " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").
") as total";
656 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
657 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
658 $sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
659 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
661 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
662 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
664 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
665 $sql .=
" AND f.fk_statut > 0";
666 $sql .=
" AND fd.product_type <= 2";
667 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
672 dol_syslog(
'htdocs/accountancy/customer/index.php');
673 $resql = $db->query($sql);
675 $num = $db->num_rows(
$resql);
677 while ($row = $db->fetch_row(
$resql)) {
678 print
'<tr><td>'.$row[0].
'</td>';
679 for ($i = 1; $i <= 12; $i++) {
680 print
'<td class="right nowraponall amount">'.price(
price2num($row[$i])).
'</td>';
682 print
'<td class="right nowraponall amount"><b>'.price(
price2num($row[13])).
'</b></td>';
687 print $db->lasterror();
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Class to manage accounting accounts.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice lines.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
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...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessage($mesgs, $style='mesgs')
Set event message 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.
img_next($titlealt='default', $moreatt='')
Show next logo.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.