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';
38$langs->loadLangs(array(
"compta",
"bills",
"other",
"accountancy"));
54$year_end = $year_start + 1;
55$month_end = $month_start - 1;
60$search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
62$year_current = $year_start;
65$action =
GETPOST(
'action',
'aZ09');
70if (!isModEnabled(
'accounting')) {
73if ($user->socid > 0) {
76if (!$user->hasRight(
'accounting',
'bind',
'write')) {
85if (($action ==
'clean' || $action ==
'validatehistory') && $user->hasRight(
'accounting',
'bind',
'write')) {
88 $sql1 =
"UPDATE ".$db->prefix().
"facturedet as fd";
89 $sql1 .=
" SET fk_code_ventilation = 0";
90 $sql1 .=
' WHERE fd.fk_code_ventilation NOT IN';
91 $sql1 .=
' (SELECT accnt.rowid ';
92 $sql1 .=
' FROM '.$db->prefix().
'accounting_account as accnt';
93 $sql1 .=
' INNER JOIN '.$db->prefix().
'accounting_system as syst';
94 $sql1 .=
" ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid = ".((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
" AND accnt.entity = ".((
int) $conf->entity).
")";
95 $sql1 .=
" AND fd.fk_facture IN (SELECT rowid FROM ".$db->prefix().
"facture WHERE entity = ".((int) $conf->entity).
")";
96 $sql1 .=
" AND fk_code_ventilation <> 0";
98 dol_syslog(
"htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
99 $resql1 = $db->query($sql1);
110if ($action ==
'validatehistory' && $user->hasRight(
'accounting',
'bind',
'write')) {
120 $sql =
"SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype, f.situation_cycle_ref, f.fk_facture_source,";
121 $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,";
122 $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,";
124 $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,";
126 $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,";
128 $sql .=
" aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
129 $sql .=
" co.code as country_code, co.label as country_label,";
130 $sql .=
" s.tva_intra,";
132 $sql .=
" spe.accountancy_code_sell as company_code_sell";
134 $sql .=
" s.accountancy_code_sell as company_code_sell";
136 $sql .=
" FROM ".$db->prefix().
"facture as f";
137 $sql .=
" INNER JOIN ".$db->prefix().
"societe as s ON s.rowid = f.fk_soc";
139 $sql .=
" LEFT JOIN " . $db->prefix() .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
141 $sql .=
" LEFT JOIN ".$db->prefix().
"c_country as co ON co.rowid = s.fk_pays ";
142 $sql .=
" INNER JOIN ".$db->prefix().
"facturedet as l ON f.rowid = l.fk_facture";
143 $sql .=
" LEFT JOIN ".$db->prefix().
"product as p ON p.rowid = l.fk_product";
145 $sql .=
" LEFT JOIN " . $db->prefix() .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
147 $alias_societe_perentity = !
getDolGlobalString(
'MAIN_COMPANY_PERENTITY_SHARED') ?
"s" :
"spe";
148 $alias_product_perentity = !
getDolGlobalString(
'MAIN_PRODUCT_PERENTITY_SHARED') ?
"p" :
"ppe";
149 $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;
150 $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;
151 $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;
152 $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;
153 $sql .=
" WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
154 $sql .=
" AND l.product_type <= 2";
155 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
157 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
159 if ($validatemonth && $validateyear) {
163 dol_syslog(
'htdocs/accountancy/customer/index.php');
165 $result = $db->query($sql);
170 $num_lines = $db->num_rows($result);
172 $facture_static =
new Facture($db);
174 $isSellerInEEC =
isInEEC($mysoc);
176 $thirdpartystatic =
new Societe($db);
177 $facture_static =
new Facture($db);
179 $product_static =
new Product($db);
182 while ($i < min($num_lines, 10000)) {
183 $objp = $db->fetch_object($result);
185 $thirdpartystatic->id = !empty($objp->socid) ? $objp->socid : 0;
186 $thirdpartystatic->name = !empty($objp->name) ? $objp->name :
"";
187 $thirdpartystatic->client = !empty($objp->client) ? $objp->client :
"";
188 $thirdpartystatic->fournisseur = !empty($objp->fournisseur) ? $objp->fournisseur :
"";
189 $thirdpartystatic->code_client = !empty($objp->code_client) ? $objp->code_client :
"";
190 $thirdpartystatic->code_compta_client = !empty($objp->code_compta_client) ? $objp->code_compta_client :
"";
191 $thirdpartystatic->code_fournisseur = !empty($objp->code_fournisseur) ? $objp->code_fournisseur :
"";
192 $thirdpartystatic->code_compta_fournisseur = !empty($objp->code_compta_fournisseur) ? $objp->code_compta_fournisseur :
"";
193 $thirdpartystatic->email = !empty($objp->email) ? $objp->email :
"";
194 $thirdpartystatic->country_code = !empty($objp->country_code) ? $objp->country_code :
"";
195 $thirdpartystatic->tva_intra = !empty($objp->tva_intra) ? $objp->tva_intra :
"";
196 $thirdpartystatic->code_compta_product = !empty($objp->company_code_sell) ? $objp->company_code_sell :
"";
198 $product_static->ref = $objp->product_ref;
199 $product_static->id = $objp->product_id;
200 $product_static->type = $objp->type;
201 $product_static->label = $objp->product_label;
202 $product_static->status = !empty($objp->status) ? $objp->status : 0;
203 $product_static->status_buy = !empty($objp->status_buy) ? $objp->status_buy : 0;
204 $product_static->accountancy_code_sell = $objp->code_sell;
205 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
206 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
207 $product_static->accountancy_code_buy = !empty($objp->code_buy) ? $objp->code_buy :
"";
208 $product_static->accountancy_code_buy_intra = !empty($objp->code_buy_intra) ? $objp->code_buy_intra :
"";
209 $product_static->accountancy_code_buy_export = !empty($objp->code_buy_export) ? $objp->code_buy_export :
"";
210 $product_static->tva_tx = $objp->tva_tx_prod;
212 $facture_static->ref = $objp->ref;
213 $facture_static->id = $objp->facid;
214 $facture_static->type = $objp->ftype;
215 $facture_static->date = $db->jdate($objp->datef);
216 $facture_static->fk_facture_source = $objp->fk_facture_source;
218 $facture_static_det->id = $objp->rowid;
219 $facture_static_det->total_ht = $objp->total_ht;
220 $facture_static_det->tva_tx = $objp->tva_tx_line;
221 $facture_static_det->vat_src_code = $objp->vat_src_code;
222 $facture_static_det->product_type = $objp->type_l;
223 $facture_static_det->desc = $objp->description;
225 $accountingAccountArray = array(
226 'dom' => $objp->aarowid,
227 'intra' => $objp->aarowid_intra,
228 'export' => $objp->aarowid_export,
229 'thirdparty' => $objp->aarowid_thirdparty);
231 $code_sell_p_notset =
'';
232 $code_sell_t_notset =
'';
236 $return = $accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray,
'customer');
237 if (!is_array($return) && $return < 0) {
240 $suggestedid = $return[
'suggestedid'];
241 $suggestedaccountingaccountfor = $return[
'suggestedaccountingaccountfor'];
243 if (!empty($suggestedid) && $suggestedaccountingaccountfor !=
'' && $suggestedaccountingaccountfor !=
'eecwithoutvatnumber') {
244 $suggestedid = $return[
'suggestedid'];
250 if ($suggestedid > 0) {
251 $sqlupdate =
"UPDATE ".$db->prefix().
"facturedet";
252 $sqlupdate .=
" SET fk_code_ventilation = ".((int) $suggestedid);
253 $sqlupdate .=
" WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id);
255 $resqlupdate = $db->query($sqlupdate);
271 if ($num_lines > 10000) {
272 $notpossible += ($num_lines - 10000);
280 setEventMessages($langs->trans(
'AutomaticBindingDone', $nbbinddone, $notpossible),
null, ($notpossible ?
'warnings' :
'mesgs'));
282 setEventMessages($langs->trans(
'DoManualBindingForFailedRecord', $nbbindfailed),
null,
'warnings');
291$help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Liaisons_comptables';
293llxHeader(
'', $langs->trans(
"CustomersVentilation"), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-customer page-index');
295$textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current - 1).
'">'.
img_previous().
'</a>';
296$textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current + 1).
'">'.
img_next().
'</a>';
299print
load_fiche_titre($langs->trans(
"CustomersVentilation").
" ".$textprevyear.
" ".$langs->trans(
"Year").
" ".$year_start.
" ".$textnextyear,
'',
'title_accountancy');
301print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilCustomer").
'</span><br>';
302print
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"DescVentilMore", $langs->transnoentitiesnoconv(
"ValidateHistory"), $langs->transnoentitiesnoconv(
"ToBind")).
'<br>';
306 print
info_admin($langs->trans(
"SorryThisModuleIsNotCompatibleWithTheExperimentalFeatureOfSituationInvoices"));
312$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>';
314print_barre_liste(
img_picto(
'',
'unlink',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesNotBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1, 0, $buttonbind);
317print
'<div class="div-table-responsive-no-min">';
318print
'<table class="noborder centpercent">';
319print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
320for ($i = 1; $i <= 12; $i++) {
326 if ($cursormonth > 12) {
329 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
332 print
'<td width="60" class="right">';
333 if (!empty($tmp[
'mday'])) {
334 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
335 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
336 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/customer/list.php?'.$param.
'">';
338 print $langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT));
339 if (!empty($tmp[
'mday'])) {
344print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
346$sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
347$sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
348for ($i = 1; $i <= 12; $i++) {
353 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef) = ".((
string) $j),
"fd.total_ht",
"0").
") AS month".str_pad((
string) $j, 2,
"0", STR_PAD_LEFT).
",";
354 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef) = ".((
string) $j),
"1",
"0").
") AS nbmonth".str_pad((
string) $j, 2,
"0", STR_PAD_LEFT).
",";
356$sql .=
" SUM(fd.total_ht) as total, COUNT(fd.rowid) as nb";
357$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
358$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
359$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
360$sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
361$sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
364 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
366$sql .=
" AND f.fk_statut > 0";
367$sql .=
" AND fd.product_type <= 2";
368$sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
369$sql .=
" AND aa.account_number IS NULL";
375$sql .=
" GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label";
377dol_syslog(
'htdocs/accountancy/customer/index.php', LOG_DEBUG);
378$resql = $db->query($sql);
380 $num = $db->num_rows($resql);
382 while ($row = $db->fetch_row($resql)) {
388 print
'<tr class="oddeven">';
390 if ($row[0] ==
'tobind') {
397 if ($row[0] ==
'tobind') {
399 if ($startmonth > 12) {
402 $startyear = ($startmonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
404 if ($endmonth > 12) {
407 $endyear = ($endmonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
408 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"));
414 for ($i = 2; $i <= 13; $i++) {
415 $cursormonth = (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1) + $i - 2);
416 if ($cursormonth > 12) {
419 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
422 print
'<td class="right nowraponall amount" title="'.price($row[2*$i - 2]).
' - '.$row[2*$i - 1].
' lines">';
423 print
price($row[2*$i - 2]);
425 if (!empty(
price2num($row[2*$i - 2])) || !empty($row[2*$i - 1])) {
426 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=validatehistory&year='.$y.
'&validatemonth='.((int) $cursormonth).
'&validateyear='.((int) $cursoryear).
'&token='.
newToken().
'">';
427 print
img_picto($langs->trans(
"ValidateHistory").
' ('.$langs->trans(
'Month'.str_pad((
string) $cursormonth, 2,
'0', STR_PAD_LEFT)).
' '.$cursoryear.
')',
'link',
'class="marginleft2"');
433 print
'<td class="right nowraponall amount"><b>'.price($row[26]).
'</b></td>';
440 print
'<tr class="oddeven"><td colspan="15">';
441 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
445 print $db->lasterror();
454print_barre_liste(
img_picto(
'',
'link',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
457print
'<div class="div-table-responsive-no-min">';
458print
'<table class="noborder centpercent">';
459print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
460for ($i = 1; $i <= 12; $i++) {
466 if ($cursormonth > 12) {
469 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
472 print
'<td width="60" class="right">';
473 if (!empty($tmp[
'mday'])) {
474 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
475 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
476 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/customer/lines.php?'.$param.
'">';
478 print $langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT));
479 if (!empty($tmp[
'mday'])) {
484print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
486$sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
487$sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
488for ($i = 1; $i <= 12; $i++) {
493 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef) = ".((
int) $j),
"fd.total_ht",
"0").
") AS month".str_pad((
string) $j, 2,
"0", STR_PAD_LEFT).
",";
495$sql .=
" SUM(fd.total_ht) as total";
496$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
497$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
498$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
499$sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
500$sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
503 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
505$sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
506$sql .=
" AND f.fk_statut > 0";
507$sql .=
" AND fd.product_type <= 2";
513$sql .=
" AND aa.account_number IS NOT NULL";
514$sql .=
" GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label";
515$sql .=
' ORDER BY aa.account_number';
517dol_syslog(
'htdocs/accountancy/customer/index.php');
518$resql = $db->query($sql);
520 $num = $db->num_rows($resql);
522 while ($row = $db->fetch_row($resql)) {
528 print
'<tr class="oddeven">';
529 print
'<td class="tdoverflowmax300"'.(empty($row[1]) ?
'' :
' title="'.dol_escape_htmltag($row[1]).
'"').
'>';
530 if ($row[0] ==
'tobind') {
535 if ($row[0] ==
'tobind') {
536 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/customer/list.php?search_year='.((
int) $y), $langs->transnoentitiesnoconv(
"ToBind"));
542 for ($i = 2; $i <= 13; $i++) {
543 $cursormonth = (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1) + $i - 2);
544 if ($cursormonth > 12) {
547 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
550 print
'<td class="right nowraponall amount">';
551 print
price($row[$i]);
554 print
'<td class="right nowraponall amount"><b>'.price($row[14]).
'</b></td>';
560 print
'<tr class="oddeven"><td colspan="15">';
561 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
565 print $db->lasterror();
575 print_barre_liste($langs->trans(
"OtherInfo"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
578 print
'<div class="div-table-responsive-no-min">';
579 print
'<table class="noborder centpercent">';
580 print
'<tr class="liste_titre"><td class="left">'.$langs->trans(
"TotalVente").
'</td>';
581 for ($i = 1; $i <= 12; $i++) {
586 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
588 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
590 $sql =
"SELECT '".$db->escape($langs->trans(
"TotalVente")).
"' AS total,";
591 for ($i = 1; $i <= 12; $i++) {
596 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef) = ".((
int) $j),
"fd.total_ht",
"0").
") AS month".str_pad((
string) $j, 2,
"0", STR_PAD_LEFT).
",";
598 $sql .=
" SUM(fd.total_ht) as total";
599 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
600 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
601 $sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
602 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
605 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
607 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
608 $sql .=
" AND f.fk_statut > 0";
609 $sql .=
" AND fd.product_type <= 2";
616 dol_syslog(
'htdocs/accountancy/customer/index.php');
617 $resql = $db->query($sql);
619 $num = $db->num_rows($resql);
621 while ($row = $db->fetch_row($resql)) {
622 print
'<tr><td>'.$row[0].
'</td>';
623 for ($i = 1; $i <= 12; $i++) {
624 print
'<td class="right nowraponall amount">'.price($row[$i]).
'</td>';
626 print
'<td class="right nowraponall amount"><b>'.price($row[13]).
'</b></td>';
631 print $db->lasterror();
636 if (isModEnabled(
'margin')) {
638 print
'<div class="div-table-responsive-no-min">';
639 print
'<table class="noborder centpercent">';
640 print
'<tr class="liste_titre"><td>'.$langs->trans(
"TotalMarge").
'</td>';
641 for ($i = 1; $i <= 12; $i++) {
646 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
648 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
652 $sql =
"SELECT '".$db->escape($langs->trans(
"Vide")).
"' AS marge,";
653 for ($i = 1; $i <= 12; $i++) {
658 $sql .=
" SUM(".$db->ifsql(
659 "MONTH(f.datef) = ".((
int) $j),
662 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))",
663 " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))"
666 ).
") AS month".str_pad((
string) $j, 2,
'0', STR_PAD_LEFT).
",";
668 $sql .=
" SUM(".$db->ifsql(
670 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))",
671 " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))"
674 $sql =
"SELECT '".$db->escape($langs->trans(
"Vide")).
"' AS marge,";
675 for ($i = 1; $i <= 12; $i++) {
680 $sql .=
" SUM(".$db->ifsql(
681 "MONTH(f.datef) = ".((
int) $j),
684 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty)))",
685 " (fd.total_ht - (fd.buy_price_ht * fd.qty))"
688 ).
") AS month".str_pad((
string) $j, 2,
'0', STR_PAD_LEFT).
",";
690 $sql .=
" SUM(".$db->ifsql(
692 " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty)))",
693 " (fd.total_ht - (fd.buy_price_ht * fd.qty))"
696 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
697 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
698 $sql .=
" WHERE f.datef >= '".$db->idate($search_date_start).
"'";
699 $sql .=
" AND f.datef <= '".$db->idate($search_date_end).
"'";
702 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
704 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
705 $sql .=
" AND f.fk_statut > 0";
706 $sql .=
" AND fd.product_type <= 2";
712 dol_syslog(
'htdocs/accountancy/customer/index.php');
713 $resql = $db->query($sql);
715 $num = $db->num_rows($resql);
717 while ($row = $db->fetch_row($resql)) {
718 print
'<tr><td>'.$row[0].
'</td>';
719 for ($i = 1; $i <= 12; $i++) {
720 print
'<td class="right nowraponall amount">'.price(
price2num($row[$i])).
'</td>';
722 print
'<td class="right nowraponall amount"><b>'.price(
price2num($row[13])).
'</b></td>';
727 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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.