-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
synchro_compta.php
215 lines (169 loc) · 7.04 KB
/
synchro_compta.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
$langs->load("companies");
$langs->load("users");
$langs->load("trips");
$langs->load("banks");
$idAccount=isset($_GET["account"])?$_GET["account"]:$_POST["account"];
if ($_GET["action"] == 'confirm_ndf_to_account' && $_GET["confirm"] == "yes"):
$idTrip = $_GET['idTrip'];
$expensereport = new ExpenseReport($db);
$expensereport->fetch($idTrip,$user);
$dateop = dol_mktime(12,0,0,$datePaiement[1],$datePaiement[2],$datePaiement[0]);
$operation = $expensereport->code_paiement;
$label = "Règlement ".$expensereport->ref;
$amount = - price2num($expensereport->total_ttc);
$num_chq = '';
$cat1 = '';
$user = new User($db);
$user->fetch($user->id);
$acct=new Account($db,$idAccount);
$insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user);
if ($insertid > 0):
$sql = " UPDATE ".MAIN_DB_PREFIX."expensereport as d";
$sql.= " SET integration_compta = 1, fk_bank_account = $idAccount";
$sql.= " WHERE rowid = $idTrip";
$resql=$db->query($sql);
if($result):
Header("Location: ".$_SERVER["PHP_SELF"]."?account=".$idAccount);
exit;
else:
dol_print_error($db);
endif;
else:
dol_print_error($db,$acct->error);
endif;
endif;
if ($_GET["action"] == 'confirm_account_to_ndf' && $_GET["confirm"] == "yes"):
$idTrip = $_GET['idTrip'];
$expensereport = new ExpenseReport($db);
$expensereport->fetch($idTrip,$user);
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank";
$sql.= " WHERE label LIKE '%".$expensereport->ref."%'";
$resql=$db->query($sql);
if ($resql > 0):
$sql = " UPDATE ".MAIN_DB_PREFIX."expensereport as d";
$sql.= " SET integration_compta = 0, fk_bank_account = 0";
$sql.= " WHERE rowid = $idTrip";
$resql=$db->query($sql);
if($result):
Header("Location: ".$_SERVER["PHP_SELF"]."?account=".$idAccount);
exit;
else:
dol_print_error($db);
endif;
else:
dol_print_error($db);
endif;
endif;
/*
* Actions
*/
llxHeader();
$html = new Form($db);
$submit = isset($_POST['submit'])?true:false;
$idAccount=isset($_GET["account"])?$_GET["account"]:$_POST["account"];
print load_fiche_titre($langs->trans("TripSynch"));
dol_fiche_head('');
if ($_GET["action"] == 'ndfTOaccount'):
$idTrip = $_GET['idTrip'];
$ret=$html->form_confirm($_SERVER["PHP_SELF"]."?idTrip=".$idTrip."&account=".$idAccount,$langs->trans("ndfToAccount"),$langs->trans("ConfirmNdfToAccount"),"confirm_ndf_to_account","","",1);
if ($ret == 'html') print '<br />';
endif;
if ($_GET["action"] == 'accountTOndf'):
$idTrip = $_GET['idTrip'];
$ret=$html->form_confirm($_SERVER["PHP_SELF"]."?idTrip=".$idTrip."&account=".$idAccount,$langs->trans("AccountToNdf"),$langs->trans("ConfirmAccountToNdf"),"confirm_account_to_ndf","","",1);
if ($ret == 'html') print '<br />';
endif;
if(empty($submit) && empty($idAccount)):
print "<form name='add' method=\"post\" action=\"synchro_compta.php\">";
print 'Choix du compte ';
print $html->select_comptes($_POST['account'],'account',0,'',1);
print ' <input type="submit" name="submit" class="button" value="'.$langs->trans("ViewAccountSynch").'">';
print "</form>";
else:
print "<form name='add' method=\"post\" action=\"synchro_compta.php\">";
print 'Choix du compte ';
print $html->select_comptes($idAccount,'account',0,'',1);
print ' <input type="submit" class="button" value="'.$langs->trans("ViewAccountSynch").'">';
print "</form>";
$sql = "SELECT d.fk_bank_account, d.ref, d.rowid, d.date_valid, d.fk_user_author, d.total_ttc, d.integration_compta, d.fk_statut";
$sql.= " ,CONCAT(u.firstname,' ',u.lastname) as declarant_NDF";
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON d.fk_user_author = u.rowid";
$sql.= " WHERE d.fk_statut = 6";
$sql.= " ORDER BY d.date_valid DESC";
$resql=$db->query($sql);
if ($resql):
$num = $db->num_rows($resql); $i = 0;
if($num>0):
$account=new Account($db);
$account->fetch($idAccount);
print '<br>';
print "<table class='noborder' width='80%'>";
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Ref").'</td>';
print '<td>'.$langs->trans("DateValidation").'</td>';
print '<td>'.$langs->trans("USER_AUTHOR").'</td>';
print '<td align="center">'.$langs->trans("TotalTTC").'</td>';
print '<td align="center">Actions</td>';
print '<td>Compte</td>';
print '<td align="center">Int.</td>';
print '</tr>';
while($i<$num):
$objp = $db->fetch_object($resql);
$var=!$var;
print '<tr'. $bc[$var].'>';
print '<td>'.$objp->ref.'</td>';
print '<td>'.dol_print_date($db->jdate($objp->date_valid),'day').'</td>';
print '<td><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$objp->fk_user_author.'">'.img_object($langs->trans("ShowUser"),"user").' '.$objp->declarant_NDF.'</a></td>';
print '<td align="center">'.$objp->total_ttc.' '.$langs->trans("EURO").'</td>';
if($objp->integration_compta)
{
print '<td align="center"><a href="synchro_compta.php?action=accountTOndf&idTrip='.$objp->rowid.'&account='.$idAccount.'"><img src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/1leftarrow.png" style="border:0px;" alt="Compte vers NDF" title="Compte vers NDF"/></a></td>';
}
else
{
print '<td align="center"><a href="synchro_compta.php?action=ndfTOaccount&idTrip='.$objp->rowid.'&account='.$idAccount.'"><img src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/1rightarrow.png" style="border:0px;" alt="NDF vers Compte" title="NDF vers Compte"/></a></td>';
}
print '<td>'.$account->label.'</td>';
if($objp->integration_compta)
{
print '<td align="center"><img src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/tick.png" style="border:0px;" alt="Intégration OK" /></td>';
}
else
{
print '<td align="center"><img src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/off.png" style="border:0px;" alt="Intégration Non OK" /></td>';
}
print "</tr>";
$i++;
endwhile;
print "</table>";
else:
print '<div class="error">'.$langs->trans("NoTripToSync").'</div>';
endif;
$db->free($resql);
else:
dol_print_error($db);
endif;
endif;
dol_fiche_end();
llxFooter();
$db->close();