From a4a72d64c033a775d031628c500d503d0f436fe5 Mon Sep 17 00:00:00 2001
From: aspangaro <alexandre.spangaro@gmail.com>
Date: Sun, 6 Sep 2015 06:43:40 +0200
Subject: [PATCH] New: Accountancy Add message when general ledger is witten

---
 htdocs/accountancy/journal/bankjournal.php    |  2 +-
 .../accountancy/journal/purchasesjournal.php  | 23 ++++++++++++++++---
 htdocs/accountancy/journal/sellsjournal.php   | 23 ++++++++++++++++---
 htdocs/langs/en_US/accountancy.lang           |  3 ++-
 4 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php
index ac6317d9d1f..c97cde97b14 100644
--- a/htdocs/accountancy/journal/bankjournal.php
+++ b/htdocs/accountancy/journal/bankjournal.php
@@ -402,7 +402,7 @@ if ($action == 'writeBookKeeping')
 	}
 
 	if (empty($error)) {
-		setEventMessage($langs->trans('Success'), 'mesgs');
+		setEventMessage($langs->trans("GeneralLedgerIsWritten"),'mesgs');
 	}
 }
 // Export
diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php
index 705434365fa..14e77e20f3f 100644
--- a/htdocs/accountancy/journal/purchasesjournal.php
+++ b/htdocs/accountancy/journal/purchasesjournal.php
@@ -157,6 +157,7 @@ if ($result) {
 // Bookkeeping Write
 if ($action == 'writebookkeeping') {
 	$now = dol_now();
+	$error = 0;
 
 	foreach ( $tabfac as $key => $val ) {
 		foreach ( $tabttc[$key] as $k => $mt ) {
@@ -179,7 +180,11 @@ if ($action == 'writebookkeeping') {
 			$bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
 			$bookkeeping->fk_user_author = $user->id;
 
-			$bookkeeping->create();
+			$result = $bookkeeping->create();
+			if ($result < 0) {
+				$error ++;
+				setEventMessage($object->errors, 'errors');
+			}
 		}
 
 		// Product / Service
@@ -205,7 +210,11 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
 					$bookkeeping->fk_user_author = $user->id;
 
-					$bookkeeping->create();
+					$result = $bookkeeping->create();
+					if ($result < 0) {
+						$error ++;
+						setEventMessage($object->errors, 'errors');
+					}
 				}
 			}
 		}
@@ -232,10 +241,18 @@ if ($action == 'writebookkeeping') {
 				$bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
 				$bookkeeping->fk_user_author = $user->id;
 
-				$bookkeeping->create();
+				$result = $bookkeeping->create();
+				if ($result < 0) {
+					$error ++;
+					setEventMessage($object->errors, 'errors');
+				}
 			}
 		}
 	}
+
+	if (empty($error)) {
+		setEventMessage($langs->trans("GeneralLedgerIsWritten"),'mesgs');
+	}
 }
 
 
diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php
index 1dd6975ea34..9eb6d67f56b 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -170,6 +170,7 @@ if ($result) {
 // Bookkeeping Write
 if ($action == 'writebookkeeping') {
 	$now = dol_now();
+	$error = 0;
 
 	foreach ( $tabfac as $key => $val ) {
 		foreach ( $tabttc[$key] as $k => $mt ) {
@@ -190,7 +191,11 @@ if ($action == 'writebookkeeping') {
 			$bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
 			$bookkeeping->fk_user_author = $user->id;
 
-			$bookkeeping->create();
+			$result = $bookkeeping->create();
+			if ($result < 0) {
+				$error ++;
+				setEventMessage($object->errors, 'errors');
+			}
 		}
 
 		// Product / Service
@@ -216,7 +221,11 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
 					$bookkeeping->fk_user_author = $user->id;
 
-					$bookkeeping->create();
+					$result = $bookkeeping->create();
+					if ($result < 0) {
+						$error ++;
+						setEventMessage($object->errors, 'errors');
+					}
 				}
 			}
 		}
@@ -242,10 +251,18 @@ if ($action == 'writebookkeeping') {
 				$bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
 				$bookkeeping->fk_user_author = $user->id;
 
-				$bookkeeping->create();
+				$result = $bookkeeping->create();
+				if ($result < 0) {
+					$error ++;
+					setEventMessage($object->errors, 'errors');
+				}
 			}
 		}
 	}
+
+	if (empty($error)) {
+		setEventMessage($langs->trans("GeneralLedgerIsWritten"),'mesgs');
+	}
 }
 // Export
 if ($action == 'export_csv') {
diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang
index b09dab7f764..57ce6b09201 100644
--- a/htdocs/langs/en_US/accountancy.lang
+++ b/htdocs/langs/en_US/accountancy.lang
@@ -157,4 +157,5 @@ ValidateHistory=Validate Automatically
 
 ErrorAccountancyCodeIsAlreadyUse=Error, you cannot delete this accounting account because it is used
 
-FicheVentilation=Breakdown card
\ No newline at end of file
+FicheVentilation=Breakdown card
+GeneralLedgerIsWritten=Operations are written in the general ledger
\ No newline at end of file
-- 
GitLab