瀏覽代碼

FIX multicompany compatibility and fix reports

Laurent Destailleur 7 年之前
父節點
當前提交
0dfc9af72a

+ 13 - 11
htdocs/accountancy/admin/journals_list.php

@@ -177,6 +177,11 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
 	    	$msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
 	    }*/
 	}
+	if (! GETPOST('label','alpha'))
+	{
+		setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
+		$ok=0;
+	}
 
 	// Clean some parameters
 	if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]='';	// If empty, we force to null
@@ -208,7 +213,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
 		if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
 			$sql.= $tabrowid[$id].",";
 		$sql.= $tabfieldinsert[$id];
-		$sql.=",active)";
+		$sql.=",active,entity)";
 		$sql.= " VALUES(";
 
 		// List of values
@@ -221,11 +226,11 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
 				$_POST[$listfieldvalue[$i]] = $conf->entity;
 			}
 			if ($i) $sql.=",";
-			if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null";  // For vat, we want/accept code = ''
+			if ($_POST[$listfieldvalue[$i]] == '') $sql.="null";  // For vat, we want/accept code = ''
 			else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
 			$i++;
 		}
-		$sql.=",1)";
+		$sql.=",1,".$conf->entity.")";
 
 		dol_syslog("actionadd", LOG_DEBUG);
 		$result = $db->query($sql);
@@ -275,6 +280,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
 			$i++;
 		}
 		$sql.= " WHERE ".$rowidcol." = '".$rowid."'";
+		$sql.=" AND entity = ".$conf->entity;
 
 		dol_syslog("actionmodify", LOG_DEBUG);
 		//print $sql;
@@ -298,6 +304,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes')       // delete
 	else { $rowidcol="rowid"; }
 
 	$sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
+	$sql.=" AND entity = ".$conf->entity;
 
 	dol_syslog("delete", LOG_DEBUG);
 	$result = $db->query($sql);
@@ -326,6 +333,7 @@ if ($action == $acts[0])
 	elseif ($code) {
 		$sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$code."'";
 	}
+	$sql.=" AND entity = ".$conf->entity;
 
 	$result = $db->query($sql);
 	if (!$result)
@@ -346,6 +354,7 @@ if ($action == $acts[1])
 	elseif ($code) {
 		$sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$code."'";
 	}
+	$sql.=" AND entity = ".$conf->entity;
 
 	$result = $db->query($sql);
 	if (!$result)
@@ -389,13 +398,7 @@ if ($id)
 {
 	// Complete requete recherche valeurs avec critere de tri
 	$sql=$tabsql[$id];
-
-	if ($search_country_id > 0)
-	{
-		if (preg_match('/ WHERE /',$sql)) $sql.= " AND ";
-		else $sql.=" WHERE ";
-		$sql.= " c.rowid = ".$search_country_id;
-	}
+	$sql.= " WHERE a.entity = ".$conf->entity;
 
 	if ($sortfield)
 	{
@@ -416,7 +419,6 @@ if ($id)
 	}
 	$sql.=$tabsqlsort[$id];
 	$sql.=$db->plimit($listlimit+1,$offset);
-	//print $sql;
 
 	$fieldlist=explode(',',$tabfield[$id]);
 

+ 3 - 2
htdocs/accountancy/journal/bankjournal.php

@@ -455,6 +455,7 @@ if (! $error && $action == 'writebookkeeping') {
 					// No subledger_account value for the bank line but add a specific label_operation
 					$bookkeeping->subledger_account = '';
 					$bookkeeping->label_operation = $reflabel;
+					$bookkeeping->entity = $conf->entity;
 
 					$totaldebit += $bookkeeping->debit;
 					$totalcredit += $bookkeeping->credit;
@@ -561,8 +562,8 @@ if (! $error && $action == 'writebookkeeping') {
 								$bookkeeping->label_compte = '';
 							}
 						}
-
 						$bookkeeping->label_operation = $reflabel;
+						$bookkeeping->entity = $conf->entity;
 
 						$totaldebit += $bookkeeping->debit;
 						$totalcredit += $bookkeeping->credit;
@@ -608,8 +609,8 @@ if (! $error && $action == 'writebookkeeping') {
 						$bookkeeping->fk_user_author = $user->id;
 						$bookkeeping->date_create = $now;
 						$bookkeeping->label_compte = '';
-
 						$bookkeeping->label_operation = $reflabel;
+						$bookkeeping->entity = $conf->entity;
 
 						$totaldebit += $bookkeeping->debit;
 						$totalcredit += $bookkeeping->credit;

+ 3 - 0
htdocs/accountancy/journal/expensereportsjournal.php

@@ -216,6 +216,7 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->code_journal = $journal;
 					$bookkeeping->journal_label = $journal_label;
 					$bookkeeping->fk_user_author = $user->id;
+					$bookkeeping->entity = $conf->entity;
 
 					$totaldebit += $bookkeeping->debit;
 					$totalcredit += $bookkeeping->credit;
@@ -265,6 +266,7 @@ if ($action == 'writebookkeeping') {
 						$bookkeeping->code_journal = $journal;
 						$bookkeeping->journal_label = $journal_label;
 						$bookkeeping->fk_user_author = $user->id;
+						$bookkeeping->entity = $conf->entity;
 
 						$totaldebit += $bookkeeping->debit;
 						$totalcredit += $bookkeeping->credit;
@@ -320,6 +322,7 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->code_journal = $journal;
 					$bookkeeping->journal_label = $journal_label;
 					$bookkeeping->fk_user_author = $user->id;
+					$bookkeeping->entity = $conf->entity;
 
 					$totaldebit += $bookkeeping->debit;
 					$totalcredit += $bookkeeping->credit;

+ 4 - 0
htdocs/accountancy/journal/purchasesjournal.php

@@ -318,6 +318,7 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->code_journal = $journal;
 					$bookkeeping->journal_label = $journal_label;
 					$bookkeeping->fk_user_author = $user->id;
+					$bookkeeping->entity = $conf->entity;
 
 					$totaldebit += $bookkeeping->debit;
 					$totalcredit += $bookkeeping->credit;
@@ -371,6 +372,7 @@ if ($action == 'writebookkeeping') {
 						$bookkeeping->code_journal = $journal;
 						$bookkeeping->journal_label = $journal_label;
 						$bookkeeping->fk_user_author = $user->id;
+						$bookkeeping->entity = $conf->entity;
 
 						$totaldebit += $bookkeeping->debit;
 						$totalcredit += $bookkeeping->credit;
@@ -430,6 +432,7 @@ if ($action == 'writebookkeeping') {
 						$bookkeeping->code_journal = $journal;
 						$bookkeeping->journal_label = $journal_label;
 						$bookkeeping->fk_user_author = $user->id;
+						$bookkeeping->entity = $conf->entity;
 
 						$totaldebit += $bookkeeping->debit;
 						$totalcredit += $bookkeeping->credit;
@@ -482,6 +485,7 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->code_journal = $journal;
 					$bookkeeping->journal_label = $journal_label;
 					$bookkeeping->fk_user_author = $user->id;
+					$bookkeeping->entity = $conf->entity;
 
 					$totaldebit += $bookkeeping->debit;
 					$totalcredit += $bookkeeping->credit;

+ 4 - 0
htdocs/accountancy/journal/sellsjournal.php

@@ -121,6 +121,7 @@ if ($in_bookkeeping == 'notyet')
 //	$sql .= " AND fd.rowid NOT IN (SELECT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";		// Useless, we save one line for all products with same account
 }
 $sql .= " ORDER BY f.datef";
+//print $sql;
 
 dol_syslog('accountancy/journal/sellsjournal.php', LOG_DEBUG);
 $result = $db->query($sql);
@@ -319,6 +320,7 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->code_journal = $journal;
 					$bookkeeping->journal_label = $journal_label;
 					$bookkeeping->fk_user_author = $user->id;
+					$bookkeeping->entity = $conf->entity;
 
 					$totaldebit += $bookkeeping->debit;
 					$totalcredit += $bookkeeping->credit;
@@ -372,6 +374,7 @@ if ($action == 'writebookkeeping') {
 						$bookkeeping->code_journal = $journal;
 						$bookkeeping->journal_label = $journal_label;
 						$bookkeeping->fk_user_author = $user->id;
+						$bookkeeping->entity = $conf->entity;
 
 						$totaldebit += $bookkeeping->debit;
 						$totalcredit += $bookkeeping->credit;
@@ -430,6 +433,7 @@ if ($action == 'writebookkeeping') {
 						$bookkeeping->code_journal = $journal;
 						$bookkeeping->journal_label = $journal_label;
 						$bookkeeping->fk_user_author = $user->id;
+						$bookkeeping->entity = $conf->entity;
 
 						$totaldebit += $bookkeeping->debit;
 						$totalcredit += $bookkeeping->credit;

+ 1 - 1
htdocs/compta/resultat/clientfourn.php

@@ -255,7 +255,7 @@ if ($modecompta == 'BOOKKEEPING')
 	$sql.= " WHERE f.numero_compte = aa.account_number";
 	//$sql.= " AND fk_statut in (1,2)";
 	$sql.= " AND ".$predefinedgroupwhere;
-	$sql.= " AND aa.fk_pcg_version = '".$charofaccountstring."'";
+	$sql.= " AND f.entity = ".$conf->entity;
 	if (! empty($date_start) && ! empty($date_end))
 		$sql.= " AND f.doc_date >= '".$db->idate($date_start)."' AND f.doc_date <= '".$db->idate($date_end)."'";
 	$sql.= " GROUP BY pcg_type, pcg_subtype, name, socid";

+ 0 - 1
htdocs/compta/resultat/index.php

@@ -828,7 +828,6 @@ if (! empty($conf->accounting->enabled) && ($modecompta == 'BOOKKEEPING'))
 	if (! empty($date_start) && ! empty($date_end))
 		$sql.= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'";
 	$sql.= " GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
-
 	//print $sql;
 
 	dol_syslog("get bookkeeping record");

+ 12 - 12
htdocs/compta/stats/index.php

@@ -142,9 +142,7 @@ else if ($modecompta=="BOOKKEEPING")
 	$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
 	$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);
 	$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
-	$description=$langs->trans("RulesCADue");
-	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.= $langs->trans("DepositsAreNotIncluded");
-	else  $description.= $langs->trans("DepositsAreIncluded");
+	$description=$langs->trans("RulesCATotalSaleJournal");
 	$builddate=dol_now();
 	//$exportlink=$langs->trans("NotYetAvailable");
 }
@@ -187,15 +185,14 @@ if ($socid) $sql.= " AND f.fk_soc = ".$socid;
 else if ($modecompta=="BOOKKEEPING")
 {
 	$sql  = "SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.credit) as amount_ttc";
-	$sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b";
-	$sql.= " WHERE b.numero_compte IN (SELECT a.account_number" ;
-	$sql.= " FROM ".MAIN_DB_PREFIX."accounting_account as a";
-	$sql.= " WHERE a.fk_accounting_category = 1 ) " ; // todo sql with accounting category, but we need to define category in turnover
+	$sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_journal as aj";
+	$sql.= " WHERE b.entity = ".$conf->entity;
+	$sql.= " AND b.code_journal = aj.code AND aj.nature = 2" ; // @TODO currently count amount in sale journal, but we need to define a category group for turnover
 }
 
-
 $sql.= " GROUP BY dm";
 $sql.= " ORDER BY dm";
+//print $sql;
 
 $result = $db->query($sql);
 if ($result)
@@ -221,7 +218,7 @@ else {
 }
 
 // On ajoute les paiements anciennes version, non lies par paiement_facture (very old versions)
-if ($modecompta != 'CREANCES-DETTES')
+if ($modecompta == 'RECETTES-DEPENSES')
 {
 	$sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
 	$sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
@@ -269,10 +266,11 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
 {
 	if ($modecompta == 'CREANCES-DETTES') print '<td align="center" width="10%" colspan="3">';
 	else print '<td align="center" width="10%" colspan="2" class="borderrightlight">';
-	print '<a href="casoc.php?year='.$annee.'">';
+	if ($modecompta != 'BOOKKEEPING') print '<a href="casoc.php?year='.$annee.'">';
 	print $annee;
     if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee+1);
-	print '</a></td>';
+    if ($modecompta != 'BOOKKEEPING') print '</a>';
+    print '</td>';
 	if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
 }
 print '</tr>';
@@ -336,7 +334,9 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
 			if ($cum[$case])
 			{
 				$now_show_delta=1;  // On a trouve le premier mois de la premiere annee generant du chiffre.
-				print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta?'&modecompta='.$modecompta:'').'">'.price($cum[$case],1).'</a>';
+				if ($modecompta != 'BOOKKEEPING') print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta?'&modecompta='.$modecompta:'').'">';
+				print price($cum[$case], 1);
+				if ($modecompta != 'BOOKKEEPING') print '</a>';
 			}
 			else
 			{

+ 1 - 0
htdocs/langs/en_US/compta.lang

@@ -157,6 +157,7 @@ RulesResultDue=- It includes outstanding invoices, expenses, VAT, donations whet
 RulesResultInOut=- It includes the real payments made on invoices, expenses, VAT and salaries. <br>- It is based on the payment dates of the invoices, expenses, VAT and salaries. The donation date for donation.
 RulesCADue=- It includes the client's due invoices whether they are paid or not. <br>- It is based on the validation date of these invoices.<br>
 RulesCAIn=- It includes all the effective payments of invoices received from clients.<br>- It is based on the payment date of these invoices<br>
+RulesCATotalSaleJournal=It includes all credit lines from the Sale journal.
 RulesAmountOnInOutBookkeepingRecord=It includes record in your Ledger with accounting accounts that has the group "EXPENSE" or "INCOME"
 RulesResultBookkeepingPredefined=It includes record in your Ledger with accounting accounts that has the group "EXPENSE" or "INCOME"
 RulesResultBookkeepingPersonalized=It show record in your Ledger with accounting accounts <b>grouped by personalized groups</b>