30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
47$langs->loadLangs(array(
"compta",
"bills",
"other",
"accountancy"));
63$year_end = $year_start + 1;
64$month_end = $month_start - 1;
69$search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
71$year_current = $year_start;
74$action =
GETPOST(
'action',
'aZ09');
79if (!isModEnabled(
'accounting')) {
82if ($user->socid > 0) {
85if (!$user->hasRight(
'accounting',
'bind',
'write')) {
94if (($action ==
'clean' || $action ==
'validatehistory') && $user->hasRight(
'accounting',
'bind',
'write')) {
98 $sql1 =
"UPDATE ".$db->prefix().
"facturedet as fd";
99 $sql1 .=
" SET fk_code_ventilation = 0";
100 $sql1 .=
' WHERE fd.fk_code_ventilation NOT IN';
101 $sql1 .=
' (SELECT accnt.rowid ';
102 $sql1 .=
' FROM '.$db->prefix().
'accounting_account as accnt';
103 $sql1 .=
' INNER JOIN '.$db->prefix().
'accounting_system as syst';
104 $sql1 .=
" ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid = ".((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
" AND accnt.entity = ".((
int)
$conf->entity).
")";
105 $sql1 .=
" AND fd.fk_facture IN (SELECT rowid FROM ".$db->prefix().
"facture WHERE entity = ".((int)
$conf->entity).
")";
106 $sql1 .=
" AND fk_code_ventilation <> 0";
108 dol_syslog(
"htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
109 $resql1 = $db->query($sql1);
120if ($action ==
'validatehistory' && $user->hasRight(
'accounting',
'bind',
'write')) {
130 $sql =
"SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype, f.situation_cycle_ref, f.fk_facture_source,";
131 $sql .=
" l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.situation_percent, l.tva_tx as tva_tx_line, l.vat_src_code,";
132 $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,";
134 $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,";
136 $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,";
138 $sql .=
" aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
139 $sql .=
" co.code as country_code, co.label as country_label,";
140 $sql .=
" s.tva_intra,";
142 $sql .=
" spe.accountancy_code_sell as company_code_sell";
144 $sql .=
" s.accountancy_code_sell as company_code_sell";
146 $sql .=
" FROM ".$db->prefix().
"facture as f";
147 $sql .=
" INNER JOIN ".$db->prefix().
"societe as s ON s.rowid = f.fk_soc";
149 $sql .=
" LEFT JOIN " . $db->prefix() .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
151 $sql .=
" LEFT JOIN ".$db->prefix().
"c_country as co ON co.rowid = s.fk_pays ";
152 $sql .=
" INNER JOIN ".$db->prefix().
"facturedet as l ON f.rowid = l.fk_facture";
153 $sql .=
" LEFT JOIN ".$db->prefix().
"product as p ON p.rowid = l.fk_product";
155 $sql .=
" LEFT JOIN " . $db->prefix() .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int)
$conf->entity);
157 $alias_societe_perentity = !
getDolGlobalString(
'MAIN_COMPANY_PERENTITY_SHARED') ?
"s" :
"spe";
158 $alias_product_perentity = !
getDolGlobalString(
'MAIN_PRODUCT_PERENTITY_SHARED') ?
"p" :
"ppe";
159 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_account as aa ON ".$db->sanitize($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;
160 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_account as aa2 ON ".$db->sanitize($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;
161 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_account as aa3 ON ".$db->sanitize($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;
162 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_account as aa4 ON ".$db->sanitize($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;
163 $sql .=
" WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
164 $sql .=
" AND l.product_type <= 2";
165 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
167 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
169 if ($validatemonth && $validateyear) {
173 dol_syslog(
'htdocs/accountancy/customer/index.php');
175 $result = $db->query($sql);
180 $num_lines = $db->num_rows($result);
182 $facture_static =
new Facture($db);
184 $isSellerInEEC =
isInEEC($mysoc);
186 $thirdpartystatic =
new Societe($db);
187 $facture_static =
new Facture($db);
189 $product_static =
new Product($db);
192 while ($i < min($num_lines, 10000)) {
193 $objp = $db->fetch_object($result);
195 $thirdpartystatic->id = !empty($objp->socid) ? $objp->socid : 0;
196 $thirdpartystatic->name = !empty($objp->name) ? $objp->name :
"";
197 $thirdpartystatic->client = !empty($objp->client) ? $objp->client :
"";
198 $thirdpartystatic->fournisseur = !empty($objp->fournisseur) ? $objp->fournisseur :
"";
199 $thirdpartystatic->code_client = !empty($objp->code_client) ? $objp->code_client :
"";
200 $thirdpartystatic->code_compta_client = !empty($objp->code_compta_client) ? $objp->code_compta_client :
"";
201 $thirdpartystatic->code_fournisseur = !empty($objp->code_fournisseur) ? $objp->code_fournisseur :
"";
202 $thirdpartystatic->code_compta_fournisseur = !empty($objp->code_compta_fournisseur) ? $objp->code_compta_fournisseur :
"";
203 $thirdpartystatic->email = !empty($objp->email) ? $objp->email :
"";
204 $thirdpartystatic->country_code = !empty($objp->country_code) ? $objp->country_code :
"";
205 $thirdpartystatic->tva_intra = !empty($objp->tva_intra) ? $objp->tva_intra :
"";
206 $thirdpartystatic->code_compta_product = !empty($objp->company_code_sell) ? $objp->company_code_sell :
"";
208 $product_static->ref = $objp->product_ref;
209 $product_static->id = $objp->product_id;
210 $product_static->type = $objp->type;
211 $product_static->label = $objp->product_label;
212 $product_static->status = !empty($objp->status) ? $objp->status : 0;
213 $product_static->status_buy = !empty($objp->status_buy) ? $objp->status_buy : 0;
214 $product_static->accountancy_code_sell = $objp->code_sell;
215 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
216 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
217 $product_static->accountancy_code_buy = !empty($objp->code_buy) ? $objp->code_buy :
"";
218 $product_static->accountancy_code_buy_intra = !empty($objp->code_buy_intra) ? $objp->code_buy_intra :
"";
219 $product_static->accountancy_code_buy_export = !empty($objp->code_buy_export) ? $objp->code_buy_export :
"";
220 $product_static->tva_tx = $objp->tva_tx_prod;
222 $facture_static->ref = $objp->ref;
223 $facture_static->id = $objp->facid;
224 $facture_static->type = $objp->ftype;
225 $facture_static->date = $db->jdate($objp->datef);
226 $facture_static->fk_facture_source = $objp->fk_facture_source;
228 $facture_static_det->id = $objp->rowid;
229 $facture_static_det->total_ht = $objp->total_ht;
230 $facture_static_det->tva_tx = $objp->tva_tx_line;
231 $facture_static_det->vat_src_code = $objp->vat_src_code;
232 $facture_static_det->product_type = $objp->type_l;
233 $facture_static_det->desc = $objp->description;
235 $accountingAccountArray = array(
236 'dom' => $objp->aarowid,
237 'intra' => $objp->aarowid_intra,
238 'export' => $objp->aarowid_export,
239 'thirdparty' => $objp->aarowid_thirdparty);
241 $code_sell_p_notset =
'';
242 $code_sell_t_notset =
'';
246 $return = $accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray,
'customer');
247 if (!is_array($return) && $return < 0) {
250 $suggestedid = $return[
'suggestedid'];
251 $suggestedaccountingaccountfor = $return[
'suggestedaccountingaccountfor'];
253 if (!empty($suggestedid) && $suggestedaccountingaccountfor !=
'' && $suggestedaccountingaccountfor !=
'eecwithoutvatnumber') {
254 $suggestedid = $return[
'suggestedid'];
260 if ($suggestedid > 0) {
261 $sqlupdate =
"UPDATE ".$db->prefix().
"facturedet";
262 $sqlupdate .=
" SET fk_code_ventilation = ".((int) $suggestedid);
263 $sqlupdate .=
" WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id);
265 $resqlupdate = $db->query($sqlupdate);
281 if ($num_lines > 10000) {
282 $notpossible += ($num_lines - 10000);
290 setEventMessages($langs->trans(
'AutomaticBindingDone', $nbbinddone, $notpossible),
null, ($notpossible ?
'warnings' :
'mesgs'));
292 setEventMessages($langs->trans(
'DoManualBindingForFailedRecord', $nbbindfailed),
null,
'warnings');
301$help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Liaisons_comptables';
303llxHeader(
'', $langs->trans(
"CustomersVentilation"), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-customer page-index');
305$textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current - 1).
'">'.
img_previous().
'</a>';
306$textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current + 1).
'">'.
img_next().
'</a>';
309print
load_fiche_titre($langs->trans(
"CustomersVentilation").
" ".$textprevyear.
" ".$langs->trans(
"Year").
" ".$year_start.
" ".$textnextyear,
'',
'title_accountancy');
311print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilCustomer").
'</span><br>';
312print
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"DescVentilMore", $langs->transnoentitiesnoconv(
"ValidateHistory"), $langs->transnoentitiesnoconv(
"ToBind")).
'<br>';
316 print
info_admin($langs->trans(
"SorryThisModuleIsNotCompatibleWithTheExperimentalFeatureOfSituationInvoices"));
322$buttonbind =
'<a class="button small" href="'.$_SERVER[
'PHP_SELF'].
'?action=validatehistory&token='.
newToken().
'&year='.$year_current.
'">'.
img_picto($langs->trans(
"ValidateHistory"),
'link',
'class="pictofixedwidth fa-color-unset"').$langs->trans(
"ValidateHistory").
'</a>';
324print_barre_liste(
img_picto(
'',
'unlink',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesNotBound"), 0,
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1, 0, $buttonbind);
327print
'<div class="div-table-responsive-no-min">';
328print
'<table class="noborder centpercent">';
329print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
330for ($i = 1; $i <= 12; $i++) {
336 if ($cursormonth > 12) {
339 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
342 print
'<td width="60" class="right">';
343 if (!empty($tmp[
'mday'])) {
344 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
345 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
346 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/customer/list.php?'.$param.
'">';
348 print $langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT));
349 if (!empty($tmp[
'mday'])) {
354print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
356$sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
357$sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
358for ($i = 1; $i <= 12; $i++) {
363 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef) = ".((
string) $j),
"fd.total_ht",
"0").
") AS month".str_pad((
string) $j, 2,
"0", STR_PAD_LEFT).
",";
364 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef) = ".((
string) $j),
"1",
"0").
") AS nbmonth".str_pad((
string) $j, 2,
"0", STR_PAD_LEFT).
",";
366$sql .=
" SUM(fd.total_ht) as total, COUNT(fd.rowid) as nb";
367$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
368$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
369$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
370$sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
371$sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
374 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
376$sql .=
" AND f.fk_statut > 0";
377$sql .=
" AND fd.product_type <= 2";
378$sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
379$sql .=
" AND aa.account_number IS NULL";
385$sql .=
" GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label";
387dol_syslog(
'htdocs/accountancy/customer/index.php', LOG_DEBUG);
388$resql = $db->query($sql);
390 $num = $db->num_rows($resql);
392 while ($row = $db->fetch_row($resql)) {
398 print
'<tr class="oddeven">';
400 if ($row[0] ==
'tobind') {
407 if ($row[0] ==
'tobind') {
409 if ($startmonth > 12) {
412 $startyear = ($startmonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
414 if ($endmonth > 12) {
417 $endyear = ($endmonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
418 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/customer/list.php?search_date_startday=1&search_date_startmonth='.((
int) $startmonth).
'&search_date_startyear='.((
int) $startyear).
'&search_date_endday=&search_date_endmonth='.((
int) $endmonth).
'&search_date_endyear='.((
int) $endyear), $langs->transnoentitiesnoconv(
"ToBind"));
424 for ($i = 2; $i <= 13; $i++) {
425 $cursormonth = (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1) + $i - 2);
426 if ($cursormonth > 12) {
429 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
432 print
'<td class="right nowraponall amount" title="'.price($row[2*$i - 2]).
' - '.$row[2*$i - 1].
' lines">';
433 print
price($row[2*$i - 2]);
435 if (!empty(
price2num($row[2*$i - 2])) || !empty($row[2*$i - 1])) {
436 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=validatehistory&year='.$y.
'&validatemonth='.((int) $cursormonth).
'&validateyear='.((int) $cursoryear).
'&token='.
newToken().
'">';
437 print
img_picto($langs->trans(
"ValidateHistory").
' ('.$langs->trans(
'Month'.str_pad((
string) $cursormonth, 2,
'0', STR_PAD_LEFT)).
' '.$cursoryear.
')',
'link',
'class="marginleft2"');
443 print
'<td class="right nowraponall amount"><b>'.price($row[26]).
'</b></td>';
450 print
'<tr class="oddeven"><td colspan="15">';
451 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
455 print $db->lasterror();
464print_barre_liste(
img_picto(
'',
'link',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesBound"), 0,
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
467print
'<div class="div-table-responsive-no-min">';
468print
'<table class="noborder centpercent">';
469print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
470for ($i = 1; $i <= 12; $i++) {
476 if ($cursormonth > 12) {
479 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
482 print
'<td width="60" class="right">';
483 if (!empty($tmp[
'mday'])) {
484 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
485 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
486 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/customer/lines.php?'.$param.
'">';
488 print $langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT));
489 if (!empty($tmp[
'mday'])) {
494print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
496$sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
497$sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
498for ($i = 1; $i <= 12; $i++) {
503 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef) = ".((
int) $j),
"fd.total_ht",
"0").
") AS month".str_pad((
string) $j, 2,
"0", STR_PAD_LEFT).
",";
505$sql .=
" SUM(fd.total_ht) as total";
506$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
507$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
508$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
509$sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
510$sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
513 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
515$sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
516$sql .=
" AND f.fk_statut > 0";
517$sql .=
" AND fd.product_type <= 2";
523$sql .=
" AND aa.account_number IS NOT NULL";
524$sql .=
" GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label";
525$sql .=
' ORDER BY aa.account_number';
527dol_syslog(
'htdocs/accountancy/customer/index.php');
528$resql = $db->query($sql);
530 $num = $db->num_rows($resql);
532 while ($row = $db->fetch_row($resql)) {
538 print
'<tr class="oddeven">';
539 print
'<td class="tdoverflowmax300"'.(empty($row[1]) ?
'' :
' title="'.dol_escape_htmltag($row[1]).
'"').
'>';
540 if ($row[0] ==
'tobind') {
545 if ($row[0] ==
'tobind') {
546 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/customer/list.php?search_year='.((
int) $y), $langs->transnoentitiesnoconv(
"ToBind"));
552 for ($i = 2; $i <= 13; $i++) {
553 $cursormonth = (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1) + $i - 2);
554 if ($cursormonth > 12) {
557 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
560 print
'<td class="right nowraponall amount">';
561 print
price($row[$i]);
564 print
'<td class="right nowraponall amount"><b>'.price($row[14]).
'</b></td>';
570 print
'<tr class="oddeven"><td colspan="15">';
571 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
575 print $db->lasterror();
585 print_barre_liste($langs->trans(
"OtherInfo"), 0,
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
588 print
'<div class="div-table-responsive-no-min">';
589 print
'<table class="noborder centpercent">';
590 print
'<tr class="liste_titre"><td class="left">'.$langs->trans(
"TotalVente").
'</td>';
591 for ($i = 1; $i <= 12; $i++) {
596 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
598 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
600 $sql =
"SELECT '".$db->escape($langs->trans(
"TotalVente")).
"' AS total,";
601 for ($i = 1; $i <= 12; $i++) {
606 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef) = ".((
int) $j),
"fd.total_ht",
"0").
") AS month".str_pad((
string) $j, 2,
"0", STR_PAD_LEFT).
",";
608 $sql .=
" SUM(fd.total_ht) as total";
609 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
610 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
611 $sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
612 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
615 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
617 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
618 $sql .=
" AND f.fk_statut > 0";
619 $sql .=
" AND fd.product_type <= 2";
626 dol_syslog(
'htdocs/accountancy/customer/index.php');
627 $resql = $db->query($sql);
629 $num = $db->num_rows($resql);
631 while ($row = $db->fetch_row($resql)) {
632 print
'<tr><td>'.$row[0].
'</td>';
633 for ($i = 1; $i <= 12; $i++) {
634 print
'<td class="right nowraponall amount">'.price($row[$i]).
'</td>';
636 print
'<td class="right nowraponall amount"><b>'.price($row[13]).
'</b></td>';
641 print $db->lasterror();
646 if (isModEnabled(
'margin')) {
648 print
'<div class="div-table-responsive-no-min">';
649 print
'<table class="noborder centpercent">';
650 print
'<tr class="liste_titre"><td>'.$langs->trans(
"TotalMarge").
'</td>';
651 for ($i = 1; $i <= 12; $i++) {
656 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
658 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
662 $sql =
"SELECT '".$db->escape($langs->trans(
"Vide")).
"' AS marge,";
663 for ($i = 1; $i <= 12; $i++) {
668 $sql .=
" SUM(".$db->ifsql(
669 "MONTH(f.datef) = ".((
int) $j),
672 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))",
673 " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))"
676 ).
") AS month".str_pad((
string) $j, 2,
'0', STR_PAD_LEFT).
",";
678 $sql .=
" SUM(".$db->ifsql(
680 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))",
681 " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))"
684 $sql =
"SELECT '".$db->escape($langs->trans(
"Vide")).
"' AS marge,";
685 for ($i = 1; $i <= 12; $i++) {
690 $sql .=
" SUM(".$db->ifsql(
691 "MONTH(f.datef) = ".((
int) $j),
694 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty)))",
695 " (fd.total_ht - (fd.buy_price_ht * fd.qty))"
698 ).
") AS month".str_pad((
string) $j, 2,
'0', STR_PAD_LEFT).
",";
700 $sql .=
" SUM(".$db->ifsql(
702 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty)))",
703 " (fd.total_ht - (fd.buy_price_ht * fd.qty))"
706 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
707 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
708 $sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
709 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
712 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
714 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
715 $sql .=
" AND f.fk_statut > 0";
716 $sql .=
" AND fd.product_type <= 2";
722 dol_syslog(
'htdocs/accountancy/customer/index.php');
723 $resql = $db->query($sql);
725 $num = $db->num_rows($resql);
727 while ($row = $db->fetch_row($resql)) {
728 print
'<tr><td>'.$row[0].
'</td>';
729 for ($i = 1; $i <= 12; $i++) {
730 print
'<td class="right nowraponall amount">'.price(
price2num($row[$i])).
'</td>';
732 print
'<td class="right nowraponall amount"><b>'.price(
price2num($row[13])).
'</b></td>';
737 print $db->lasterror();
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
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)
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 information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message 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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.