diff --git a/htdocs/compta/journal/purchasesjournal.php b/htdocs/compta/journal/purchasesjournal.php index ab3d5dcb2a1..3a96441a39b 100755 --- a/htdocs/compta/journal/purchasesjournal.php +++ b/htdocs/compta/journal/purchasesjournal.php @@ -33,6 +33,13 @@ $langs->load("companies"); $langs->load("other"); $langs->load("compta"); +$date_startmonth=GETPOST('date_startmonth'); +$date_startday=GETPOST('date_startday'); +$date_startyear=GETPOST('date_startyear'); +$date_endmonth=GETPOST('date_endmonth'); +$date_endday=GETPOST('date_endday'); +$date_endyear=GETPOST('date_endyear'); + // Protection if external user if ($user->societe_id > 0) accessforbidden(); @@ -64,8 +71,8 @@ if ($pastmonth == 0) $pastmonthyear--; } -$date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); -$date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]); +$date_start=dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); +$date_end=dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); if (empty($date_start) || empty($date_end)) // We define date_start and date_end { @@ -73,7 +80,9 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end } $nom=$langs->trans("PurchasesJournal"); -//$nomlink=; +$nomlink=''; +$periodlink=''; +$exportlink=''; $builddate=time(); $description=$langs->trans("DescPurchasesJournal"); $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); diff --git a/htdocs/compta/journal/sellsjournal.php b/htdocs/compta/journal/sellsjournal.php index ea3e128c567..66e76117c8f 100755 --- a/htdocs/compta/journal/sellsjournal.php +++ b/htdocs/compta/journal/sellsjournal.php @@ -34,6 +34,13 @@ $langs->load("companies"); $langs->load("other"); $langs->load("compta"); +$date_startmonth=GETPOST('date_startmonth'); +$date_startday=GETPOST('date_startday'); +$date_startyear=GETPOST('date_startyear'); +$date_endmonth=GETPOST('date_endmonth'); +$date_endday=GETPOST('date_endday'); +$date_endyear=GETPOST('date_endyear'); + // Protection if external user if ($user->societe_id > 0) accessforbidden(); @@ -66,8 +73,8 @@ if ($pastmonth == 0) $pastmonthyear--; } -$date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); -$date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]); +$date_start=dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); +$date_end=dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); if (empty($date_start) || empty($date_end)) // We define date_start and date_end { @@ -75,7 +82,9 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end } $nom=$langs->trans("SellsJournal"); -//$nomlink=; +$nomlink=''; +$periodlink=''; +$exportlink=''; $builddate=time(); $description=$langs->trans("DescSellsJournal"); $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); @@ -113,25 +122,28 @@ if ($result) { $obj = $db->fetch_object($result); // les variables - $cptcli = (! empty($conf->global->COMPTA_ACCOUNT_CUSTOMER))?$conf->global->COMPTA_ACCOUNT_CUSTOMER:$langs->trans("CodeNotDef"); - $compta_soc = (! empty($obj->code_compta))?$obj->code_compta:$cptcli; + $cptcli = (! empty($conf->global->COMPTA_ACCOUNT_CUSTOMER)?$conf->global->COMPTA_ACCOUNT_CUSTOMER:$langs->trans("CodeNotDef")); + $compta_soc = (! empty($obj->code_compta)?$obj->code_compta:$cptcli); $compta_prod = $obj->accountancy_code_sell; if (empty($compta_prod)) { - if($obj->product_type == 0) $compta_prod = (! empty($conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT))?$conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT:$langs->trans("CodeNotDef"); - else $compta_prod = (! empty($conf->global->COMPTA_SERVICE_SOLD_ACCOUNT))?$conf->global->COMPTA_SERVICE_SOLD_ACCOUNT:$langs->trans("CodeNotDef"); + if($obj->product_type == 0) $compta_prod = (! empty($conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT)?$conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT:$langs->trans("CodeNotDef")); + else $compta_prod = (! empty($conf->global->COMPTA_SERVICE_SOLD_ACCOUNT)?$conf->global->COMPTA_SERVICE_SOLD_ACCOUNT:$langs->trans("CodeNotDef")); } - $cpttva = (! empty($conf->global->COMPTA_VAT_ACCOUNT))?$conf->global->COMPTA_VAT_ACCOUNT:$langs->trans("CodeNotDef"); - $compta_tva = (! empty($obj->accountancy_code))?$obj->accountancy_code:$cpttva; + $cpttva = (! empty($conf->global->COMPTA_VAT_ACCOUNT)?$conf->global->COMPTA_VAT_ACCOUNT:$langs->trans("CodeNotDef")); + $compta_tva = (! empty($obj->accountancy_code)?$obj->accountancy_code:$cpttva); //la ligne facture $tabfac[$obj->rowid]["date"] = $obj->datef; $tabfac[$obj->rowid]["ref"] = $obj->facnumber; $tabfac[$obj->rowid]["type"] = $obj->type; + if (! isset($tabttc[$obj->rowid][$compta_soc])) $tabttc[$obj->rowid][$compta_soc]=0; + if (! isset($tabht[$obj->rowid][$compta_prod])) $tabht[$obj->rowid][$compta_prod]=0; + if (! isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva]=0; $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc; $tabht[$obj->rowid][$compta_prod] += $obj->total_ht; $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva; - $tabcompany[$obj->rowid]=array('id'=>$obj->socid,'name'=>$obj->name,'client'=>$obj->client); + $tabcompany[$obj->rowid]=array('id'=>$obj->socid, 'name'=>$obj->name, 'client'=>$obj->client); $i++; } } @@ -217,6 +229,6 @@ print ""; // End of page -$db->close(); llxFooter(); +$db->close(); ?> \ No newline at end of file diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 830b18607bb..a2e6045fe2b 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,10 +32,18 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); $langs->load("bills"); +$date_startmonth=GETPOST('date_startmonth'); +$date_startday=GETPOST('date_startday'); +$date_startyear=GETPOST('date_startyear'); +$date_endmonth=GETPOST('date_endmonth'); +$date_endday=GETPOST('date_endday'); +$date_endyear=GETPOST('date_endyear'); + // Security check $socid = GETPOST('socid','int'); if ($user->societe_id > 0) $socid = $user->societe_id; -if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire) accessforbidden(); +if (! $user->rights->compta->resultat->lire && ! $user->rights->accounting->comptarapport->lire) + accessforbidden(); // Date range $year=GETPOST("year"); @@ -49,8 +57,8 @@ if (empty($year)) $month_current = strftime("%m",dol_now()); $year_start = $year; } -$date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); // Date for local PHP server -$date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]); // Date for local PHP server +$date_start=dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); +$date_end=dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); // Quarter if (empty($date_start) || empty($date_end)) // We define date_start and date_end { @@ -86,9 +94,7 @@ else } // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') -$modecompta = $conf->global->COMPTA_MODE; -if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta"); - +$modecompta=(GETPOST("modecompta")?GETPOST("modecompta"):$conf->global->COMPTA_MODE); /* @@ -99,6 +105,13 @@ llxHeader(); $form=new Form($db); +$nomlink=''; +$periodlink=''; +$exportlink=''; + +$total_ht=0; +$total_ttc=0; + // Affiche en-tete de rapport if ($modecompta=="CREANCES-DETTES") { @@ -128,7 +141,8 @@ report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportl print ''; print ''; print ''; -if ($modecompta == 'CREANCES-DETTES') print ""; +if ($modecompta == 'CREANCES-DETTES') + print ""; print ""; print "\n"; @@ -144,9 +158,12 @@ if ($modecompta == 'CREANCES-DETTES') $sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= " WHERE f.fk_soc = s.rowid"; $sql.= " AND f.fk_statut IN (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)"; - else $sql.= " AND f.type IN (0,1,2,3)"; - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) + $sql.= " AND f.type IN (0,1,2)"; + else + $sql.= " AND f.type IN (0,1,2,3)"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } else { @@ -162,7 +179,8 @@ else $sql.= " WHERE p.rowid = pf.fk_paiement"; $sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND f.fk_soc = s.rowid"; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql.= " AND f.fk_soc = ".$socid; @@ -183,11 +201,12 @@ if ($result) { print ""; print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; + if ($modecompta == 'CREANCES-DETTES') + print "\n"; print "\n"; - $total_ht = $total_ht + $objp->amount_ht; - $total_ttc = $total_ttc + $objp->amount_ttc; + $total_ht += (isset($objp->amount_ht)?$objp->amount_ht:0); + $total_ttc += $objp->amount_ttc; print "\n"; $i++; } @@ -208,7 +227,8 @@ if ($modecompta != 'CREANCES-DETTES') $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; $sql.= " AND ba.entity = ".$conf->entity; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " GROUP BY nom, idp"; $sql.= " ORDER BY nom"; @@ -226,11 +246,13 @@ if ($modecompta != 'CREANCES-DETTES') print ""; print "\n"; + if ($modecompta == 'CREANCES-DETTES') + print "\n"; print "\n"; - $total_ht = $total_ht + $objp->amount_ht; - $total_ttc = $total_ttc + $objp->amount_ttc; + $total_ht += (isset($objp->amount_ht)?$objp->amount_ht:0); + $total_ttc += $objp->amount_ttc; + print "\n"; $i++; } @@ -250,7 +272,8 @@ if ($total_ttc == 0) } print ''; -if ($modecompta == 'CREANCES-DETTES') print ''; +if ($modecompta == 'CREANCES-DETTES') + print ''; print ''; print ''; @@ -265,9 +288,12 @@ if ($modecompta == 'CREANCES-DETTES') $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; $sql.= " WHERE f.fk_soc = s.rowid"; $sql.= " AND f.fk_statut IN (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)"; - else $sql.= " AND f.type IN (0,1,2,3)"; - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) + $sql.= " AND f.type IN (0,1,2)"; + else + $sql.= " AND f.type IN (0,1,2,3)"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } else { @@ -279,7 +305,8 @@ else $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s"; $sql.= " ON f.fk_soc = s.rowid"; $sql.= " WHERE p.rowid = pf.fk_paiementfourn "; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql.= " AND f.fk_soc = ".$socid; @@ -306,13 +333,15 @@ if ($result) { print ""; print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; + if ($modecompta == 'CREANCES-DETTES') + print "\n"; print "\n"; - $total_ht = $total_ht - $objp->amount_ht; - $total_ttc = $total_ttc - $objp->amount_ttc; - $subtotal_ht = $subtotal_ht + $objp->amount_ht; - $subtotal_ttc = $subtotal_ttc + $objp->amount_ttc; + $total_ht -= (isset($objp->amount_ht)?$objp->amount_ht:0); + $total_ttc -= $objp->amount_ttc; + $subtotal_ht += (isset($objp->amount_ht)?$objp->amount_ht:0); + $subtotal_ttc += $objp->amount_ttc; + print "\n"; $i++; } @@ -330,7 +359,8 @@ if ($result) { dol_print_error($db); } print ''; -if ($modecompta == 'CREANCES-DETTES') print ''; +if ($modecompta == 'CREANCES-DETTES') + print ''; print ''; print ''; @@ -349,7 +379,8 @@ if ($modecompta == 'CREANCES-DETTES') $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " WHERE cs.fk_type = c.id"; $sql.= " AND c.deductible = 0"; - if ($date_start && $date_end) $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; } else { @@ -360,7 +391,8 @@ else $sql.= " WHERE p.fk_charge = cs.rowid"; $sql.= " AND cs.fk_type = c.id"; $sql.= " AND c.deductible = 0"; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND cs.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle"; @@ -378,10 +410,10 @@ if ($result) { while ($i < $num) { $obj = $db->fetch_object($result); - $total_ht = $total_ht - $obj->amount; - $total_ttc = $total_ttc - $obj->amount; - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $total_ht -= $obj->amount; + $total_ttc -= $obj->amount; + $subtotal_ht += $obj->amount; + $subtotal_ttc += $obj->amount; $var = !$var; print ""; @@ -402,7 +434,8 @@ if ($result) { dol_print_error($db); } print ''; -if ($modecompta == 'CREANCES-DETTES') print ''; +if ($modecompta == 'CREANCES-DETTES') + print ''; print ''; print ''; @@ -420,7 +453,8 @@ if ($modecompta == 'CREANCES-DETTES') $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " WHERE cs.fk_type = c.id"; $sql.= " AND c.deductible = 1"; - if ($date_start && $date_end) $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; $sql.= " AND cs.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle"; $sql.= " ORDER BY c.libelle"; @@ -434,7 +468,8 @@ else $sql.= " WHERE p.fk_charge = cs.rowid"; $sql.= " AND cs.fk_type = c.id"; $sql.= " AND c.deductible = 1"; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " AND cs.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle"; $sql.= " ORDER BY c.libelle"; @@ -452,15 +487,16 @@ if ($result) { while ($i < $num) { $obj = $db->fetch_object($result); - $total_ht = $total_ht - $obj->amount; - $total_ttc = $total_ttc - $obj->amount; - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $total_ht -= $obj->amount; + $total_ttc -= $obj->amount; + $subtotal_ht += $obj->amount; + $subtotal_ttc += $obj->amount; $var = !$var; print ""; print ''; - if ($modecompta == 'CREANCES-DETTES') print ''; + if ($modecompta == 'CREANCES-DETTES') + print ''; print ''; print ''; $i++; @@ -476,7 +512,8 @@ if ($result) { dol_print_error($db); } print ''; -if ($modecompta == 'CREANCES-DETTES') print ''; +if ($modecompta == 'CREANCES-DETTES') + print ''; print ''; print ''; @@ -488,7 +525,8 @@ if ($mysoc->tva_assuj == 'franchise') // Non assujeti print ''; print ''; - if ($modecompta == 'CREANCES-DETTES') print ''; + if ($modecompta == 'CREANCES-DETTES') + print ''; print ''; print ''; @@ -512,9 +550,12 @@ if ($modecompta == 'CREANCES-DETTES') $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.tva) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " WHERE f.fk_statut IN (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)"; - else $sql.= " AND f.type IN (0,1,2,3)"; - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) + $sql.= " AND f.type IN (0,1,2)"; + else + $sql.= " AND f.type IN (0,1,2,3)"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; $sql.= " AND f.entity = ".$conf->entity; $sql.= " GROUP BY dm"; $sql.= " ORDER BY dm"; @@ -529,11 +570,11 @@ if ($modecompta == 'CREANCES-DETTES') while ($i < $num) { $obj = $db->fetch_object($result); - $amount = $amount - $obj->amount; - //$total_ht = $total_ht - $obj->amount; - $total_ttc = $total_ttc - $obj->amount; - //$subtotal_ht = $subtotal_ht - $obj->amount; - $subtotal_ttc = $subtotal_ttc - $obj->amount; + $amount -= $obj->amount; + //$total_ht -= $obj->amount; + $total_ttc -= $obj->amount; + //$subtotal_ht -= $obj->amount; + $subtotal_ttc -= $obj->amount; $i++; } } @@ -551,9 +592,12 @@ if ($modecompta == 'CREANCES-DETTES') $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; $sql.= " WHERE f.fk_statut IN (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)"; - else $sql.= " AND f.type IN (0,1,2,3)"; - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) + $sql.= " AND f.type IN (0,1,2)"; + else + $sql.= " AND f.type IN (0,1,2,3)"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; $sql.= " AND f.entity = ".$conf->entity; $sql.= " GROUP BY dm"; $sql.= " ORDER BY dm"; @@ -568,11 +612,11 @@ if ($modecompta == 'CREANCES-DETTES') while ($i < $num) { $obj = $db->fetch_object($result); - $amount = $amount + $obj->amount; - //$total_ht = $total_ht + $obj->amount; - $total_ttc = $total_ttc + $obj->amount; - //$subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $amount += $obj->amount; + //$total_ht += $obj->amount; + $total_ttc += $obj->amount; + //$subtotal_ht += $obj->amount; + $subtotal_ttc += $obj->amount; $i++; } @@ -593,7 +637,8 @@ else $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; $sql.= " WHERE amount > 0"; - if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; $sql.= " AND t.entity = ".$conf->entity; $sql.= " GROUP BY dm"; $sql.= " ORDER BY dm"; @@ -608,11 +653,11 @@ else while ($i < $num) { $obj = $db->fetch_object($result); - $amount = $amount - $obj->amount; - $total_ht = $total_ht - $obj->amount; - $total_ttc = $total_ttc - $obj->amount; - $subtotal_ht = $subtotal_ht - $obj->amount; - $subtotal_ttc = $subtotal_ttc - $obj->amount; + $amount -= $obj->amount; + $total_ht -= $obj->amount; + $total_ttc -= $obj->amount; + $subtotal_ht -= $obj->amount; + $subtotal_ttc -= $obj->amount; $i++; } @@ -623,7 +668,8 @@ else } print ""; print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; + if ($modecompta == 'CREANCES-DETTES') + print "\n"; print "\n"; print "\n"; @@ -632,7 +678,8 @@ else $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; $sql.= " WHERE amount < 0"; - if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; + if (! empty($date_start) && ! empty($date_end)) + $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; $sql.= " AND t.entity = ".$conf->entity; $sql.= " GROUP BY dm"; $sql.= " ORDER BY dm"; @@ -647,11 +694,11 @@ else while ($i < $num) { $obj = $db->fetch_object($result); - $amount = $amount + $obj->amount; - $total_ht = $total_ht + $obj->amount; - $total_ttc = $total_ttc + $obj->amount; - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $amount += $obj->amount; + $total_ht += $obj->amount; + $total_ttc += $obj->amount; + $subtotal_ht += $obj->amount; + $subtotal_ttc += $obj->amount; $i++; } @@ -664,7 +711,8 @@ else } print ""; print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; + if ($modecompta == 'CREANCES-DETTES') + print "\n"; print "\n"; print "\n"; } @@ -673,7 +721,8 @@ else if ($mysoc->tva_assuj != 'franchise') // Assujeti { print ''; - if ($modecompta == 'CREANCES-DETTES') print ''; + if ($modecompta == 'CREANCES-DETTES') + print ''; print ''; print ''; } @@ -687,7 +736,8 @@ if ($mysoc->tva_assuj != 'franchise') // Assujeti print ''; print ''; - if ($modecompta == 'CREANCES-DETTES') print ''; + if ($modecompta == 'CREANCES-DETTES') + print ''; print ''; print ''; } diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index bbb6c5511be..2ba45b22a7d 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -40,13 +40,11 @@ else { // Security check $socid = GETPOST('socid','int'); if ($user->societe_id > 0) $socid = $user->societe_id; -if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire) -accessforbidden(); +if (! $user->rights->compta->resultat->lire && ! $user->rights->accounting->comptarapport->lire) + accessforbidden(); // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') -$modecompta = $conf->global->COMPTA_MODE; -if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta"); - +$modecompta=(GETPOST("modecompta")?GETPOST("modecompta"):$conf->global->COMPTA_MODE); /* @@ -57,6 +55,9 @@ llxHeader(); $form=new Form($db); +$nomlink=''; +$exportlink=''; + // Affiche en-tete du rapport if ($modecompta == 'CREANCES-DETTES') { @@ -125,7 +126,7 @@ if ($result) while ($i < $num) { $row = $db->fetch_object($result); - $encaiss[$row->dm] = $row->amount_ht; + $encaiss[$row->dm] = (isset($row->amount_ht)?$row->amount_ht:0); $encaiss_ttc[$row->dm] = $row->amount_ttc; $i++; } @@ -159,7 +160,10 @@ if ($modecompta != 'CREANCES-DETTES') { $row = $db->fetch_object($result); - $encaiss[$row->dm] += $row->amount_ht; + if (! isset($encaiss[$row->dm])) $encaiss[$row->dm]=0; + $encaiss[$row->dm] += (isset($row->amount_ht)?$row->amount_ht:0); + + if (! isset($encaiss_ttc[$row->dm])) $encaiss_ttc[$row->dm]=0; $encaiss_ttc[$row->dm] += $row->amount_ttc; $i++; @@ -208,7 +212,10 @@ if ($result) { $row = $db->fetch_object($result); - $decaiss[$row->dm] = $row->amount_ht; + if (! isset($decaiss[$row->dm])) $decaiss[$row->dm]=0; + $decaiss[$row->dm] = (isset($row->amount_ht)?$row->amount_ht:0); + + if (! isset($decaiss_ttc[$row->dm])) $decaiss_ttc[$row->dm]=0; $decaiss_ttc[$row->dm] = $row->amount_ttc; $i++; @@ -246,7 +253,10 @@ if ($modecompta == 'CREANCES-DETTES') while ($i < $num) { $obj = $db->fetch_object($result); + if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; $decaiss[$obj->dm] += $obj->amount; + + if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; $decaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -274,7 +284,10 @@ if ($modecompta == 'CREANCES-DETTES') while ($i < $num) { $obj = $db->fetch_object($result); + if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0; $encaiss[$obj->dm] += $obj->amount; + + if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0; $encaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -302,7 +315,10 @@ else { while ($i < $num) { $obj = $db->fetch_object($result); + if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; $decaiss[$obj->dm] += $obj->amount; + + if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; $decaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -328,7 +344,10 @@ else { while ($i < $num) { $obj = $db->fetch_object($result); + if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0; $encaiss[$obj->dm] += $obj->amount; + + if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0; $encaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -346,7 +365,7 @@ $subtotal_ht = 0; $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount_ht, sum(cs.amount) as amount_ttc"; + $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " WHERE cs.fk_type = c.id"; @@ -354,7 +373,7 @@ if ($modecompta == 'CREANCES-DETTES') } else { - $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ht, sum(p.amount) as amount_ttc"; + $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; @@ -375,8 +394,11 @@ if ($result) { while ($i < $num) { $obj = $db->fetch_object($result); - $decaiss[$obj->dm] += $obj->amount_ht; - $decaiss_ttc[$obj->dm] += $obj->amount_ttc; + if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; + $decaiss[$obj->dm] += $obj->amount; + + if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; + $decaiss_ttc[$obj->dm] += $obj->amount; $i++; } @@ -393,7 +415,7 @@ $subtotal_ht = 0; $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount_ht, sum(cs.amount) as amount_ttc"; + $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " WHERE cs.fk_type = c.id"; @@ -401,7 +423,7 @@ if ($modecompta == 'CREANCES-DETTES') } else { - $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ht, sum(p.amount) as amount_ttc"; + $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; @@ -422,8 +444,11 @@ if ($result) { while ($i < $num) { $obj = $db->fetch_object($result); - $decaiss[$obj->dm] += $obj->amount_ht; - $decaiss_ttc[$obj->dm] += $obj->amount_ttc; + if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; + $decaiss[$obj->dm] += $obj->amount; + + if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; + $decaiss_ttc[$obj->dm] += $obj->amount; $i++; } @@ -479,17 +504,19 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois_modulo,1,$annee_decalage)); print '"; print '"; @@ -523,7 +550,9 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) print ''; + $in=(isset($totentrees[$annee])?price2num($totentrees[$annee], 'MT'):0); + $out=(isset($totsorties[$annee])?price2num($totsorties[$annee],' MT'):0); + print price($in-$out).''; // print ''; } } @@ -533,6 +562,5 @@ print "
  ".$langs->trans("AmountHT")."".$langs->trans("AmountHT")."".$langs->trans("AmountTTC")."
 ".$langs->trans("Bills").' '.$objp->nom."".price($objp->amount_ht)."".price($objp->amount_ht)."".price($objp->amount_ttc)."
 ".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n"; - if ($modecompta == 'CREANCES-DETTES') print "".price($objp->amount_ht)."".price($objp->amount_ht)."".price($objp->amount_ttc)."
'.price($total_ht).''.price($total_ht).''.price($total_ttc).'
 ".$langs->trans("Bills")." socid."\">".$objp->nom."".price(-$objp->amount_ht)."".price(-$objp->amount_ht)."".price(-$objp->amount_ttc)."
'.price(-$subtotal_ht).''.price(-$subtotal_ht).''.price(-$subtotal_ttc).'
 
'.price(-$subtotal_ht).''.price(-$subtotal_ht).''.price(-$subtotal_ttc).'
 '.$obj->nom.''.price(-$obj->amount).''.price(-$obj->amount).''.price(-$obj->amount).'
'.price(-$subtotal_ht).''.price(-$subtotal_ht).''.price(-$subtotal_ttc).'
'.$langs->trans("Profit").''.price($total_ht).''.price($total_ht).''.price($total_ttc).'
 ".$langs->trans("VATPaid")."".price($amount)."".price($amount)."".price($amount)."
 ".$langs->trans("VATCollected")."".price($amount)."".price($amount)."".price($amount)."
  '.price(price2num($subtotal_ttc,'MT')).'
'.$langs->trans("Profit").''.price(price2num($total_ht,'MT')).''.price(price2num($total_ht,'MT')).''.price(price2num($total_ttc,'MT')).'
 '; - if ($decaiss_ttc[$case] != 0) + if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) { print ''.price(price2num($decaiss_ttc[$case],'MT')).''; + if (! isset($totsorties[$annee])) $totsorties[$annee]=0; $totsorties[$annee]+=$decaiss_ttc[$case]; } print " '; - if ($encaiss_ttc[$case] != 0) + if (isset($encaiss_ttc[$case]) && $encaiss_ttc[$case] != 0) { print ''.price(price2num($encaiss_ttc[$case],'MT')).''; + if (! isset($totentrees[$annee])) $totentrees[$annee]=0; $totentrees[$annee]+=$encaiss_ttc[$case]; } print " '; if (isset($totentrees[$annee]) || isset($totsorties[$annee])) { - print price(price2num($totentrees[$annee]-$totsorties[$annee],'MT')).' 
"; llxFooter(); - $db->close(); -?> +?> \ No newline at end of file diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 9a20d25f431..bacec03ef6d 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -616,7 +616,7 @@ function dol_get_fiche_head($links=array(), $active='0', $title='', $notab=0, $p $out="\n".'