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);
84$pastmonthyear = $year_current;
90$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
91$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
93if (empty($date_start) || empty($date_end)) {
98$name = $langs->trans(
"SellsJournal");
102$description = $langs->trans(
"DescSellsJournal").
'<br>';
104 $description .= $langs->trans(
"DepositsAreNotIncluded");
106 $description .= $langs->trans(
"DepositsAreIncluded");
108$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
109report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink);
114$sql =
"SELECT f.rowid, f.ref, f.type, f.datef, f.ref_client,";
115$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,";
116$sql .=
" s.rowid as socid, s.nom as name, s.code_compta, s.client,";
117$sql .=
" p.rowid as pid, p.ref as pref,";
119 $sql .=
" ppe.accountancy_code_sell,";
121 $sql .=
" p.accountancy_code_sell,";
123$sql .=
" ct.accountancy_code_sell as account_tva, ct.recuperableonly";
124$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
125$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
127 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
129$sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
130$sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
131$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);
132$sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
133$sql .=
" AND f.fk_statut > 0";
140$sql .=
" AND fd.product_type IN (0,1)";
141if ($date_start && $date_end) {
142 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
144$sql .=
" ORDER BY f.rowid";
147if (in_array($db->type, array(
'mysql',
'mysqli'))) {
148 $db->query(
'SET SQL_BIG_SELECTS=1');
151$result = $db->query($sql);
156 $tablocaltax1 = array();
157 $tablocaltax2 = array();
159 $tabcompany = array();
160 $account_localtax1 = 0;
161 $account_localtax2 = 0;
163 $num = $db->num_rows($result);
167 $obj = $db->fetch_object($result);
169 $cptcli = ((
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER') !=
"") ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans(
"CodeNotDef"));
170 $compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $cptcli);
171 $compta_prod = $obj->accountancy_code_sell;
172 if (empty($compta_prod)) {
173 if ($obj->product_type == 0) {
174 $compta_prod = (
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT') ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
176 $compta_prod = (
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT') ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
179 $cpttva = (
getDolGlobalString(
'ACCOUNTING_VAT_SOLD_ACCOUNT') ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
180 $compta_tva = (!empty($obj->account_tva) ? $obj->account_tva : $cpttva);
183 $compta_localtax1 = (!empty($account_localtax1[3]) ? $account_localtax1[3] : $langs->trans(
"CodeNotDef"));
185 $compta_localtax2 = (!empty($account_localtax2[3]) ? $account_localtax2[3] : $langs->trans(
"CodeNotDef"));
189 $line->fetch($obj->id);
193 if ($obj->situation_percent == 0) {
194 $situation_ratio = 0;
196 $prev_progress = $line->get_prev_progress($obj->rowid);
197 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
200 $situation_ratio = 1;
204 $tabfac[$obj->rowid][
"date"] = $obj->datef;
205 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
206 $tabfac[$obj->rowid][
"type"] = $obj->type;
207 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
208 $tabttc[$obj->rowid][$compta_soc] = 0;
210 if (!isset($tabht[$obj->rowid][$compta_prod])) {
211 $tabht[$obj->rowid][$compta_prod] = 0;
213 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
214 $tabtva[$obj->rowid][$compta_tva] = 0;
216 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
217 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
219 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
220 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
222 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
223 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
224 if ($obj->recuperableonly != 1) {
225 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
227 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
228 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
229 $tabcompany[$obj->rowid] = array(
'id'=>$obj->socid,
'name'=>$obj->name,
'client'=>$obj->client);
242print
'<table class="liste noborder centpercent">';
243print
'<tr class="liste_titre">';
245print
'<td>'.$langs->trans(
'Date').
'</td><td>'.$langs->trans(
'Piece').
' ('.$langs->trans(
'InvoiceRef').
')</td>';
246print
'<td>'.$langs->trans(
'Account').
'</td>';
247print
'<td>'.$langs->trans(
'Type').
'</td>';
248print
'<td class="right">'.$langs->trans(
'AccountingDebit').
'</td>';
249print
'<td class="right">'.$langs->trans(
'AccountingCredit').
'</td>';
253$invoicestatic =
new Facture($db);
254$companystatic =
new Client($db);
256foreach ($tabfac as $key => $val) {
257 $invoicestatic->id = $key;
258 $invoicestatic->ref = $val[
"ref"];
259 $invoicestatic->type = $val[
"type"];
261 $companystatic->id = $tabcompany[$key][
'id'];
262 $companystatic->name = $tabcompany[$key][
'name'];
263 $companystatic->client = $tabcompany[$key][
'client'];
267 'var' => $tabttc[$key],
268 'label' => $langs->trans(
'ThirdParty').
' ('.$companystatic->getNomUrl(0,
'customer', 16).
')',
273 'var' => $tabht[$key],
274 'label' => $langs->trans(
'Products'),
277 'var' => $tabtva[$key],
278 'label' => $langs->trans(
'VAT')
281 'var' => $tablocaltax1[$key],
282 'label' => $langs->transcountry(
'LT1', $mysoc->country_code)
285 'var' => $tablocaltax2[$key],
286 'label' => $langs->transcountry(
'LT2', $mysoc->country_code)
290 foreach ($lines as $line) {
291 foreach ($line[
'var'] as $k => $mt) {
292 if (isset($line[
'nomtcheck']) || $mt) {
293 print
'<tr class="oddeven">';
294 print
"<td>".dol_print_date($db->jdate($val[
"date"])).
"</td>";
295 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
296 print
"<td>".$k.
"</td><td>".$line[
'label'].
"</td>";
298 if (isset($line[
'inv'])) {
299 print
'<td class="right">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
300 print
'<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
302 print
'<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
303 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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.