Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
24fa2bd6
Commit
24fa2bd6
authored
20 years ago
by
Rodolphe Quiedeville
Browse files
Options
Downloads
Patches
Plain Diff
Ajout fonction AddFacture
parent
e13df824
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
htdocs/bon-prelevement.class.php
+282
-74
282 additions, 74 deletions
htdocs/bon-prelevement.class.php
with
282 additions
and
74 deletions
htdocs/bon-prelevement.class.php
+
282
−
74
View file @
24fa2bd6
...
...
@@ -60,6 +60,112 @@ class BonPrelevement
return
1
;
}
/*
*
*
*
*/
function
AddFacture
(
$facture_id
,
$client_id
,
$client_nom
,
$amount
,
$code_banque
,
$code_guichet
,
$number
)
{
$result
=
0
;
$ligne_id
=
0
;
$result
=
$this
->
AddLigne
(
$ligne_id
,
$client_id
,
$client_nom
,
$amount
,
$code_banque
,
$code_guichet
,
$number
);
if
(
$result
==
0
)
{
if
(
$ligne_id
>
0
)
{
$sql
=
"INSERT INTO "
.
MAIN_DB_PREFIX
.
"prelevement_facture "
;
$sql
.
=
" (fk_facture,fk_prelevement_lignes)"
;
$sql
.
=
" VALUES ("
.
$facture_id
.
","
.
$ligne_id
.
")"
;
if
(
$this
->
db
->
query
(
$sql
))
{
$result
=
0
;
}
else
{
$result
=
-
1
;
dolibarr_syslog
(
"BonPrelevement::AddFacture Erreur
$result
"
);
}
}
else
{
$result
=
-
2
;
dolibarr_syslog
(
"BonPrelevement::AddFacture Erreur
$result
"
);
}
}
else
{
$result
=
-
3
;
dolibarr_syslog
(
"BonPrelevement::AddFacture Erreur
$result
"
);
}
return
$result
;
}
/*
*
*
*/
function
AddLigne
(
&
$ligne_id
,
$client_id
,
$client_nom
,
$amount
,
$code_banque
,
$code_guichet
,
$number
)
{
$result
=
-
1
;
$concat
=
0
;
if
(
$concat
==
1
)
{
/*
* On aggrge les lignes
*/
$sql
=
"SELECT rowid FROM "
.
MAIN_DB_PREFIX
.
"prelevement_lignes"
;
$sql
.
=
" WHERE fk_prelevement_bons"
.
$this
->
id
;
$sql
.
=
" AND fk_soc ="
.
$client_id
;
$sql
.
=
" AND code_banque ='"
.
$code_banque
.
"'"
;
$sql
.
=
" AND code_guichet ='"
.
$code_guichet
.
"'"
;
$sql
.
=
" AND number ='"
.
$number
.
"'"
;
if
(
$this
->
db
->
query
(
$sql
))
{
$num
=
$this
->
db
->
num_rows
();
}
else
{
$result
=
-
1
;
}
}
else
{
/*
* Pas de d'agrgation
*/
$sql
=
"INSERT INTO "
.
MAIN_DB_PREFIX
.
"prelevement_lignes (fk_prelevement_bons"
;
$sql
.
=
" , fk_soc , client_nom "
;
$sql
.
=
" , amount"
;
$sql
.
=
" , code_banque , code_guichet , number)"
;
$sql
.
=
" VALUES ("
.
$this
->
id
;
$sql
.
=
","
.
$client_id
.
",'"
.
addslashes
(
$client_nom
)
.
"'"
;
$sql
.
=
",'"
.
ereg_replace
(
","
,
"."
,
$amount
)
.
"'"
;
$sql
.
=
", '
$code_banque
', '
$code_guichet
', '
$number
')"
;
if
(
$this
->
db
->
query
(
$sql
))
{
$ligne_id
=
$this
->
db
->
last_insert_id
();
$result
=
0
;
}
else
{
dolibarr_syslog
(
"BonPrelevement::AddLigne Erreur -2"
);
$result
=
-
2
;
}
}
return
$result
;
}
/*
*
*
...
...
@@ -73,7 +179,9 @@ class BonPrelevement
$sql
.
=
" , method_trans, fk_user_trans"
;
$sql
.
=
","
.
$this
->
db
->
pdate
(
"p.date_credit"
)
.
" as date_credit"
;
$sql
.
=
" , fk_user_credit"
;
$sql
.
=
" FROM "
.
MAIN_DB_PREFIX
.
"prelevement as p"
;
$sql
.
=
" FROM "
.
MAIN_DB_PREFIX
.
"prelevement_bons as p"
;
$sql
.
=
" WHERE p.rowid="
.
$rowid
;
$result
=
$this
->
db
->
query
(
$sql
);
...
...
@@ -101,13 +209,13 @@ class BonPrelevement
}
else
{
dolibarr_syslog
(
"
b
on
-p
relevment::Fetch Erreur aucune ligne retourne"
);
dolibarr_syslog
(
"
B
on
P
relev
e
ment::Fetch Erreur aucune ligne retourne"
);
return
-
1
;
}
}
else
{
dolibarr_syslog
(
"
b
on
-p
relevment::Fetch Erreur "
);
dolibarr_syslog
(
"
B
on
P
relev
e
ment::Fetch Erreur "
);
dolibarr_syslog
(
$sql
);
return
-
2
;
}
...
...
@@ -122,16 +230,14 @@ class BonPrelevement
if
(
$this
->
db
->
begin
())
{
$sql
=
" UPDATE "
.
MAIN_DB_PREFIX
.
"prelevement "
;
$sql
=
" UPDATE "
.
MAIN_DB_PREFIX
.
"prelevement_bons "
;
$sql
.
=
" SET credite = 1"
;
$sql
.
=
" WHERE rowid="
.
$this
->
id
;
$result
=
$this
->
db
->
query
(
$sql
);
if
(
!
$result
)
{
dolibarr_syslog
(
"bon-prelevment::set_credite Erreur 1"
);
dolibarr_syslog
(
"bon-prelev
e
ment::set_credite Erreur 1"
);
$error
++
;
}
...
...
@@ -157,18 +263,14 @@ class BonPrelevement
if
(
$error
==
0
)
{
/*
* Change le statut des lignes de factures
*/
$sql
=
" UPDATE "
.
MAIN_DB_PREFIX
.
"prelevement_facture "
;
$sql
.
=
" SET statut = 1"
;
$sql
.
=
" WHERE fk_prelevement="
.
$this
->
id
;
$result
=
$this
->
db
->
query
(
$sql
);
if
(
!
$result
)
$sql
=
" UPDATE "
.
MAIN_DB_PREFIX
.
"prelevement_lignes "
;
$sql
.
=
" SET statut = 2"
;
$sql
.
=
" WHERE fk_prelevement_bons="
.
$this
->
id
;
if
(
!
$this
->
db
->
query
(
$sql
))
{
dolibarr_syslog
(
"
b
on
-p
relevment::set_credit
e
Erreur
3
"
);
dolibarr_syslog
(
"
B
on
P
relev
e
ment::set_
info
credit Erreur
1
"
);
$error
++
;
}
}
...
...
@@ -184,8 +286,10 @@ class BonPrelevement
}
else
{
$this
->
db
->
rollback
();
dolibarr_syslog
(
"bon-prelevment::set_credite ROLLBACK "
);
dolibarr_syslog
(
"BonPrelevement::set_credite ROLLBACK "
);
return
-
1
;
}
...
...
@@ -194,7 +298,7 @@ class BonPrelevement
else
{
dolibarr_syslog
(
"
b
on
-p
relevment::set_credite Ouverture transaction SQL impossible "
);
dolibarr_syslog
(
"
B
on
P
relev
e
ment::set_credite Ouverture transaction SQL impossible "
);
return
-
2
;
}
}
...
...
@@ -208,18 +312,16 @@ class BonPrelevement
if
(
$this
->
db
->
begin
())
{
$sql
=
" UPDATE "
.
MAIN_DB_PREFIX
.
"prelevement "
;
$sql
=
" UPDATE "
.
MAIN_DB_PREFIX
.
"prelevement_bons "
;
$sql
.
=
" SET fk_user_credit = "
.
$user
->
id
;
$sql
.
=
" , statut = 2"
;
$sql
.
=
" , date_credit='"
.
$this
->
db
->
idate
(
$date
)
.
"'"
;
$sql
.
=
" WHERE rowid="
.
$this
->
id
;
$result
=
$this
->
db
->
query
(
$sql
);
if
(
!
$
result
)
$sql
.
=
" AND statut = 1"
;
if
(
!
$
this
->
db
->
query
(
$sql
)
)
{
dolibarr_syslog
(
"bon-prelevment::set_infotrans Erreur 1"
);
dolibarr_syslog
(
$this
->
db
->
error
());
dolibarr_syslog
(
"BonPrelevement::set_infocredit Erreur 1"
);
$error
++
;
}
...
...
@@ -234,15 +336,17 @@ class BonPrelevement
}
else
{
$this
->
db
->
rollback
();
dolibarr_syslog
(
"bon-prelevment::set_infotrans ROLLBACK "
);
return
-
1
;
}
}
else
{
dolibarr_syslog
(
"bon-prelevment::set_info
trans
Ouverture transaction SQL impossible "
);
dolibarr_syslog
(
"bon-prelev
e
ment::set_info
credit
Ouverture transaction SQL impossible "
);
return
-
2
;
}
}
...
...
@@ -257,17 +361,17 @@ class BonPrelevement
if
(
$this
->
db
->
begin
())
{
$sql
=
" UPDATE "
.
MAIN_DB_PREFIX
.
"prelevement "
;
$sql
=
" UPDATE "
.
MAIN_DB_PREFIX
.
"prelevement_bons "
;
$sql
.
=
" SET fk_user_trans = "
.
$user
->
id
;
$sql
.
=
" , date_trans='"
.
$this
->
db
->
idate
(
$date
)
.
"'"
;
$sql
.
=
" , method_trans="
.
$method
;
$sql
.
=
" , statut = 1"
;
$sql
.
=
" WHERE rowid="
.
$this
->
id
;
$sql
.
=
" AND statut = 0"
;
$result
=
$this
->
db
->
query
(
$sql
);
if
(
!
$result
)
if
(
!
$this
->
db
->
query
(
$sql
))
{
dolibarr_syslog
(
"bon-prelevment::set_infotrans Erreur 1"
);
dolibarr_syslog
(
"bon-prelev
e
ment::set_infotrans Erreur 1"
);
dolibarr_syslog
(
$this
->
db
->
error
());
$error
++
;
}
...
...
@@ -284,14 +388,15 @@ class BonPrelevement
else
{
$this
->
db
->
rollback
();
dolibarr_syslog
(
"bon-prelevment::set_infotrans ROLLBACK "
);
dolibarr_syslog
(
"BonPrelevement::set_infotrans ROLLBACK "
);
return
-
1
;
}
}
else
{
dolibarr_syslog
(
"
b
on
-p
relevment::set_infotrans Ouverture transaction SQL impossible "
);
dolibarr_syslog
(
"
B
on
P
relev
e
ment::set_infotrans Ouverture transaction SQL impossible "
);
return
-
2
;
}
}
...
...
@@ -344,48 +449,86 @@ class BonPrelevement
*/
function
Generate
()
{
$this
->
EnregEmetteur
();
$result
=
-
1
;
/*
* En-tete Emetteur
*/
$
nbfactures
=
sizeof
(
$this
->
factures
);
$
this
->
EnregEmetteur
(
);
/*
* Lignes
*/
$this
->
total
=
0
;
$sql
=
"SELECT rowid, client_nom, code_banque, code_guichet, number, amount"
;
$sql
.
=
" FROM "
.
MAIN_DB_PREFIX
.
"prelevement_lignes"
;
$sql
.
=
" WHERE fk_prelevement_bons = "
.
$this
->
id
;
$i
=
0
;
if
(
$this
->
db
->
query
(
$sql
))
{
$num
=
$this
->
db
->
num_rows
();
while
(
$i
<
$num
)
{
$row
=
$this
->
db
->
fetch_row
();
$this
->
EnregDestinataire
(
$row
[
0
],
$row
[
1
],
$row
[
2
],
$row
[
3
],
$row
[
4
],
$row
[
5
]);
$this
->
total
=
$this
->
total
+
$row
[
5
];
$i
++
;
}
}
else
{
$result
=
-
2
;
}
/*
$nbfactures = sizeof($this->factures);
for ($i = 0 ; $i < $nbfactures ; $i++)
{
$fac = new Facture($this->db);
$fac->fetch($this->factures[$i]);
$fac->fetch_client();
$fac
->
client
->
rib
();
// Set client->bank_account
if
(
$fac
->
client
->
bank_account
->
verif
())
{
$fac->client->rib();
if ($fac->client->bank_account->verif()) {
$this->total = $this->total + $fac->total_ttc;
$this->EnregDestinataire($fac);
}
else
{
}else{
print $fac->client->bank_account->error_message;
print
$fac
->
client
->
nom
;
}
print $fac->client->nom; }
}
*/
/*
* Pied de page total
*/
$this
->
EnregTotal
(
$this
->
total
);
fclose
(
$this
->
file
);
return
$result
;
}
/*
* Enregistrements destinataires
*
*
*/
function
Enreg
Emetteur
(
)
function
Enreg
Destinataire
(
$rowid
,
$client_nom
,
$rib_banque
,
$rib_guichet
,
$rib_number
,
$amount
)
{
fputs
(
$this
->
file
,
"0
3
"
);
fputs
(
$this
->
file
,
"0
6
"
);
fputs
(
$this
->
file
,
"08"
);
// Prlvement ordinaire
fputs
(
$this
->
file
,
" "
);
// Zone Rserve B2
...
...
@@ -398,60 +541,56 @@ class BonPrelevement
fputs
(
$this
->
file
,
strftime
(
"%d%m"
,
$this
->
date_echeance
));
fputs
(
$this
->
file
,
substr
(
strftime
(
"%y"
,
$this
->
date_echeance
),
1
));
// Raison Sociale C2
// Raison Sociale
Destinataire
C2
fputs
(
$this
->
file
,
substr
(
$
this
->
raison_sociale
.
" "
,
0
,
24
));
fputs
(
$this
->
file
,
substr
(
$
client
->
nom
.
" "
,
0
,
24
));
//
Reference de la remise crancier D1 sur 7 caractres
//
Domiciliation facultative D1
fputs
(
$this
->
file
,
substr
(
$this
->
reference_remise
.
" "
,
0
,
7
));
// Zone Rserve D1-2
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
17
));
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
24
));
// Zone Rserve D2
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
2
));
fputs
(
$this
->
file
,
"E"
);
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
5
));
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
8
));
// Code Guichet D3
fputs
(
$this
->
file
,
$
this
->
emetteur_code
_guichet
);
fputs
(
$this
->
file
,
$
rib
_guichet
);
// Numero de compte D4
fputs
(
$this
->
file
,
substr
(
"000000000000000"
.
$
this
->
emetteur
_numer
o_compte
,
-
11
));
fputs
(
$this
->
file
,
substr
(
"000000000000000"
.
$
rib
_num
b
er
,
-
11
));
// Zone
Rserve E
// Zone
E Montant
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
16
)
);
$montant
=
(
round
(
$amount
,
2
)
*
100
);
// Zone Rserve F
fputs
(
$this
->
file
,
substr
(
"000000000000000"
.
$montant
,
-
16
));
// Libell F
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
31
));
fputs
(
$this
->
file
,
substr
(
"*"
.
$this
->
ref
.
$rowid
.
" "
,
0
,
13
));
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
18
));
// Code tablissement
// Code tablissement
G1
fputs
(
$this
->
file
,
$
this
->
emetteur_code_etablissement
);
fputs
(
$this
->
file
,
$
rib_banque
);
// Zone Rserve G
// Zone Rserve G
2
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
5
));
fputs
(
$this
->
file
,
"
\n
"
);
}
/*
* Enregistrements destinataires
*
*
*/
function
EnregDestinataire
(
$fac
)
function
EnregDestinataireVersion1
(
$fac
)
{
fputs
(
$this
->
file
,
"06"
);
fputs
(
$this
->
file
,
"08"
);
// Prlvement ordinaire
...
...
@@ -508,6 +647,75 @@ class BonPrelevement
fputs
(
$this
->
file
,
"
\n
"
);
}
/*
*
*
*/
function
EnregEmetteur
()
{
fputs
(
$this
->
file
,
"03"
);
fputs
(
$this
->
file
,
"08"
);
// Prlvement ordinaire
fputs
(
$this
->
file
,
" "
);
// Zone Rserve B2
fputs
(
$this
->
file
,
$this
->
numero_national_emetteur
);
// Numro National d'emmetteur B3
// Date d'chance C1
fputs
(
$this
->
file
,
" "
);
fputs
(
$this
->
file
,
strftime
(
"%d%m"
,
$this
->
date_echeance
));
fputs
(
$this
->
file
,
substr
(
strftime
(
"%y"
,
$this
->
date_echeance
),
1
));
// Raison Sociale C2
fputs
(
$this
->
file
,
substr
(
$this
->
raison_sociale
.
" "
,
0
,
24
));
// Reference de la remise crancier D1 sur 7 caractres
fputs
(
$this
->
file
,
substr
(
$this
->
reference_remise
.
" "
,
0
,
7
));
// Zone Rserve D1-2
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
17
));
// Zone Rserve D2
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
2
));
fputs
(
$this
->
file
,
"E"
);
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
5
));
// Code Guichet D3
fputs
(
$this
->
file
,
$this
->
emetteur_code_guichet
);
// Numero de compte D4
fputs
(
$this
->
file
,
substr
(
"000000000000000"
.
$this
->
emetteur_numero_compte
,
-
11
));
// Zone Rserve E
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
16
));
// Zone Rserve F
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
31
));
// Code tablissement
fputs
(
$this
->
file
,
$this
->
emetteur_code_etablissement
);
// Zone Rserve G
fputs
(
$this
->
file
,
substr
(
" "
,
0
,
5
));
fputs
(
$this
->
file
,
"
\n
"
);
}
/*
* Pied de page
*
*/
function
EnregTotal
(
$total
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment