34require
'../../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
41$langs->loadLangs(array(
'companies',
'other',
'bills',
'compta'));
43$date_startmonth =
GETPOST(
'date_startmonth');
44$date_startday =
GETPOST(
'date_startday');
45$date_startyear =
GETPOST(
'date_startyear');
46$date_endmonth =
GETPOST(
'date_endmonth');
47$date_endday =
GETPOST(
'date_endday');
48$date_endyear =
GETPOST(
'date_endyear');
51if ($user->socid > 0) {
52 $socid = $user->socid;
54if (isModEnabled(
'comptabilite')) {
57if (isModEnabled(
'accounting')) {
58 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
60$hookmanager->initHooks([
'selljournallist']);
76$morequery =
'&date_startyear='.$date_startyear.
'&date_startmonth='.$date_startmonth.
'&date_startday='.$date_startday.
'&date_endyear='.$date_endyear.
'&date_endmonth='.$date_endmonth.
'&date_endday='.$date_endday;
78llxHeader(
'', $langs->trans(
"SellsJournal"),
'',
'', 0, 0,
'',
'', $morequery);
82$pastmonth = strftime(
"%m",
dol_now()) - 1;
83$pastmonthyear = $year_current;
89$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
90$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
92if (empty($date_start) || empty($date_end)) {
97$name = $langs->trans(
"SellsJournal");
101$description = $langs->trans(
"DescSellsJournal").
'<br>';
102if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
103 $description .= $langs->trans(
"DepositsAreNotIncluded");
105 $description .= $langs->trans(
"DepositsAreIncluded");
107$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
108report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink);
110$p = explode(
":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
113$sql =
"SELECT f.rowid, f.ref, f.type, f.datef, f.ref_client,";
114$sql .=
" fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.total_ttc, fd.localtax1_tx, fd.localtax2_tx, fd.total_localtax1, fd.total_localtax2, fd.rowid as id, fd.situation_percent,";
115$sql .=
" s.rowid as socid, s.nom as name, s.code_compta, s.client,";
116$sql .=
" p.rowid as pid, p.ref as pref,";
117if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
118 $sql .=
" ppe.accountancy_code_sell,";
120 $sql .=
" p.accountancy_code_sell,";
122$sql .=
" ct.accountancy_code_sell as account_tva, ct.recuperableonly";
123$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
124$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
125if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
126 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
128$sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
129$sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
130$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_tva ct ON fd.tva_tx = ct.taux AND fd.info_bits = ct.recuperableonly AND ct.fk_pays = ".((int) $idpays);
131$sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
132$sql .=
" AND f.fk_statut > 0";
133if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
139$sql .=
" AND fd.product_type IN (0,1)";
140if ($date_start && $date_end) {
141 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
143$sql .=
" ORDER BY f.rowid";
146if (in_array($db->type, array(
'mysql',
'mysqli'))) {
147 $db->query(
'SET SQL_BIG_SELECTS=1');
150$result = $db->query($sql);
155 $tablocaltax1 = array();
156 $tablocaltax2 = array();
158 $tabcompany = array();
159 $account_localtax1 = 0;
160 $account_localtax2 = 0;
162 $num = $db->num_rows($result);
166 $obj = $db->fetch_object($result);
168 $cptcli = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER !=
"") ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans(
"CodeNotDef"));
169 $compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $cptcli);
170 $compta_prod = $obj->accountancy_code_sell;
171 if (empty($compta_prod)) {
172 if ($obj->product_type == 0) {
173 $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
175 $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
178 $cpttva = (!empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
179 $compta_tva = (!empty($obj->account_tva) ? $obj->account_tva : $cpttva);
182 $compta_localtax1 = (!empty($account_localtax1[3]) ? $account_localtax1[3] : $langs->trans(
"CodeNotDef"));
184 $compta_localtax2 = (!empty($account_localtax2[3]) ? $account_localtax2[3] : $langs->trans(
"CodeNotDef"));
188 $line->fetch($obj->id);
192 if ($obj->situation_percent == 0) {
193 $situation_ratio = 0;
195 $prev_progress = $line->get_prev_progress($obj->rowid);
196 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
199 $situation_ratio = 1;
203 $tabfac[$obj->rowid][
"date"] = $obj->datef;
204 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
205 $tabfac[$obj->rowid][
"type"] = $obj->type;
206 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
207 $tabttc[$obj->rowid][$compta_soc] = 0;
209 if (!isset($tabht[$obj->rowid][$compta_prod])) {
210 $tabht[$obj->rowid][$compta_prod] = 0;
212 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
213 $tabtva[$obj->rowid][$compta_tva] = 0;
215 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
216 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
218 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
219 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
221 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
222 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
223 if ($obj->recuperableonly != 1) {
224 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
226 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
227 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
228 $tabcompany[$obj->rowid] = array(
'id'=>$obj->socid,
'name'=>$obj->name,
'client'=>$obj->client);
241print
'<table class="liste noborder centpercent">';
242print
'<tr class="liste_titre">';
244print
'<td>'.$langs->trans(
'Date').
'</td><td>'.$langs->trans(
'Piece').
' ('.$langs->trans(
'InvoiceRef').
')</td>';
245print
'<td>'.$langs->trans(
'Account').
'</td>';
246print
'<td>'.$langs->trans(
'Type').
'</td>';
247print
'<td class="right">'.$langs->trans(
'AccountingDebit').
'</td>';
248print
'<td class="right">'.$langs->trans(
'AccountingCredit').
'</td>';
252$invoicestatic =
new Facture($db);
253$companystatic =
new Client($db);
255foreach ($tabfac as $key => $val) {
256 $invoicestatic->id = $key;
257 $invoicestatic->ref = $val[
"ref"];
258 $invoicestatic->type = $val[
"type"];
260 $companystatic->id = $tabcompany[$key][
'id'];
261 $companystatic->name = $tabcompany[$key][
'name'];
262 $companystatic->client = $tabcompany[$key][
'client'];
266 'var' => $tabttc[$key],
267 'label' => $langs->trans(
'ThirdParty').
' ('.$companystatic->getNomUrl(0,
'customer', 16).
')',
272 'var' => $tabht[$key],
273 'label' => $langs->trans(
'Products'),
276 'var' => $tabtva[$key],
277 'label' => $langs->trans(
'VAT')
280 'var' => $tablocaltax1[$key],
281 'label' => $langs->transcountry(
'LT1', $mysoc->country_code)
284 'var' => $tablocaltax2[$key],
285 'label' => $langs->transcountry(
'LT2', $mysoc->country_code)
289 foreach ($lines as $line) {
290 foreach ($line[
'var'] as $k => $mt) {
291 if (isset($line[
'nomtcheck']) || $mt) {
292 print
'<tr class="oddeven">';
293 print
"<td>".dol_print_date($db->jdate($val[
"date"])).
"</td>";
294 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
295 print
"<td>".$k.
"</td><td>".$line[
'label'].
"</td>";
297 if (isset($line[
'inv'])) {
298 print
'<td class="right">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
299 print
'<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
301 print
'<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
302 print
'<td class="right">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage customers or prospects.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice lines.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
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...
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.