35require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
51$langs->loadLangs(array(
'companies',
'other',
'bills',
'compta'));
53$date_startmonth =
GETPOST(
'date_startmonth');
54$date_startday =
GETPOST(
'date_startday');
55$date_startyear =
GETPOST(
'date_startyear');
56$date_endmonth =
GETPOST(
'date_endmonth');
57$date_endday =
GETPOST(
'date_endday');
58$date_endyear =
GETPOST(
'date_endyear');
61if ($user->socid > 0) {
62 $socid = $user->socid;
66$hookmanager->initHooks([
'selljournallist']);
68if (isModEnabled(
'comptabilite')) {
71if (isModEnabled(
'accounting')) {
72 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
89$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;
91llxHeader(
'', $langs->trans(
"SellsJournal"),
'',
'', 0, 0,
'',
'', $morequery);
97$pastmonthyear = $year_current;
103$date_start =
dol_mktime(0, 0, 0, (
int) $date_startmonth, (
int) $date_startday, (
int) $date_startyear);
104$date_end =
dol_mktime(23, 59, 59, (
int) $date_endmonth, (
int) $date_endday, (
int) $date_endyear);
106if (empty($date_start) || empty($date_end)) {
111$name = $langs->trans(
"SellsJournal");
115$description = $langs->trans(
"DescSellsJournal").
'<br>';
117 $description .= $langs->trans(
"DepositsAreNotIncluded");
119 $description .= $langs->trans(
"DepositsAreIncluded");
121$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
122report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink);
127$sql =
"SELECT f.rowid, f.ref, f.type, f.datef, f.ref_client, f.situation_cycle_ref,";
128$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,";
129$sql .=
" s.rowid as socid, s.nom as name, s.code_compta as code_compta_client, s.client,";
130$sql .=
" p.rowid as pid, p.ref as pref,";
132 $sql .=
" ppe.accountancy_code_sell,";
134 $sql .=
" p.accountancy_code_sell,";
136$sql .=
" ct.accountancy_code_sell as account_tva, ct.recuperableonly";
137$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
138$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
140 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int)
$conf->entity);
142$sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
143$sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
144$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);
145$sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
146$sql .=
" AND ct.entity IN (".getEntity(
'invoice').
")";
147$sql .=
" AND f.fk_statut > 0";
154$sql .=
" AND fd.product_type IN (0,1)";
155if ($date_start && $date_end) {
156 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
158$sql .=
" ORDER BY f.rowid";
161if (in_array($db->type, array(
'mysql',
'mysqli'))) {
162 $db->query(
'SET SQL_BIG_SELECTS=1');
167$result = $db->query($sql);
171 $tablocaltax1 = array();
172 $tablocaltax2 = array();
174 $tabcompany = array();
175 $account_localtax1 = 0;
176 $account_localtax2 = 0;
178 $num = $db->num_rows($result);
182 $obj = $db->fetch_object($result);
184 $cptcli = ((
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER') !=
"") ?
$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans(
"CodeNotDef"));
185 $compta_soc = (!empty($obj->code_compta_client) ? $obj->code_compta_client : $cptcli);
186 $compta_prod = $obj->accountancy_code_sell;
187 if (empty($compta_prod)) {
188 if ($obj->product_type == 0) {
189 $compta_prod = (
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT') ?
$conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
191 $compta_prod = (
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT') ?
$conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
194 $cpttva = (
getDolGlobalString(
'ACCOUNTING_VAT_SOLD_ACCOUNT') ?
$conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
195 $compta_tva = (!empty($obj->account_tva) ? $obj->account_tva : $cpttva);
198 $compta_localtax1 = (!empty($account_localtax1[3]) ? $account_localtax1[3] : $langs->trans(
"CodeNotDef"));
200 $compta_localtax2 = (!empty($account_localtax2[3]) ? $account_localtax2[3] : $langs->trans(
"CodeNotDef"));
204 $line->fetch($obj->id);
206 if ($obj->situation_cycle_ref > 0) {
208 if ($obj->situation_percent == 0) {
209 $situation_ratio = 0;
211 $prev_progress = $line->get_prev_progress($obj->rowid);
212 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
215 $situation_ratio = 1;
219 $tabfac[$obj->rowid][
"date"] = $obj->datef;
220 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
221 $tabfac[$obj->rowid][
"type"] = $obj->type;
222 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
223 $tabttc[$obj->rowid][$compta_soc] = 0;
225 if (!isset($tabht[$obj->rowid][$compta_prod])) {
226 $tabht[$obj->rowid][$compta_prod] = 0;
228 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
229 $tabtva[$obj->rowid][$compta_tva] = 0;
231 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
232 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
234 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
235 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
237 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
238 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
239 if ($obj->recuperableonly != 1) {
240 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
242 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
243 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
244 $tabcompany[$obj->rowid] = array(
'id' => $obj->socid,
'name' => $obj->name,
'client' => $obj->client);
257print
'<table class="liste noborder centpercent">';
258print
'<tr class="liste_titre">';
260print
'<td>'.$langs->trans(
'Date').
'</td><td>'.$langs->trans(
'Piece').
' ('.$langs->trans(
'InvoiceRef').
')</td>';
261print
'<td>'.$langs->trans(
'Account').
'</td>';
262print
'<td>'.$langs->trans(
'Type').
'</td>';
263print
'<td class="right">'.$langs->trans(
'AccountingDebit').
'</td>';
264print
'<td class="right">'.$langs->trans(
'AccountingCredit').
'</td>';
268$invoicestatic =
new Facture($db);
269$companystatic =
new Client($db);
271foreach ($tabfac as $key => $val) {
272 $invoicestatic->id = $key;
273 $invoicestatic->ref = $val[
"ref"];
274 $invoicestatic->type = $val[
"type"];
276 $companystatic->id = $tabcompany[$key][
'id'];
277 $companystatic->name = $tabcompany[$key][
'name'];
278 $companystatic->client = $tabcompany[$key][
'client'];
282 'var' => $tabttc[$key],
283 'label' => $langs->trans(
'ThirdParty').
' ('.$companystatic->getNomUrl(0,
'customer', 16).
')',
288 'var' => $tabht[$key],
289 'label' => $langs->trans(
'Products'),
292 'var' => $tabtva[$key],
293 'label' => $langs->trans(
'VAT')
296 'var' => $tablocaltax1[$key],
297 'label' => $langs->transcountry(
'LT1', $mysoc->country_code)
300 'var' => $tablocaltax2[$key],
301 'label' => $langs->transcountry(
'LT2', $mysoc->country_code)
305 foreach ($lines as $line) {
306 foreach ($line[
'var'] as $k => $mt) {
307 if (isset($line[
'nomtcheck']) || $mt) {
308 print
'<tr class="oddeven">';
309 print
"<td>".dol_print_date($db->jdate($val[
"date"])).
"</td>";
310 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
311 print
"<td>".$k.
"</td><td>".$line[
'label'].
"</td>";
313 if (isset($line[
'inv'])) {
314 print
'<td class="right">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
315 print
'<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
317 print
'<td class="right">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
318 print
'<td class="right">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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 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 information (by default a local PHP server timestamp) Rep...
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.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
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).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.