26if (!defined(
'NOSESSION')) {
27 define(
'NOSESSION',
'1');
30$sapi_type = php_sapi_name();
31$script_file = basename(__FILE__);
35if (substr($sapi_type, 0, 3) ==
'cgi') {
36 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
40require_once $path.
"../../htdocs/master.inc.php";
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/paymentsocialcontribution.class.php';
56$version = DOL_VERSION;
64print
"***** ".$script_file.
" (".$version.
") pid=".
dol_getmypid().
" *****\n";
65dol_syslog($script_file.
" launched with arg ".join(
',', $argv));
67if (!isset($argv[3]) || !$argv[3]) {
68 print
"Usage: ".$script_file.
" bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
76$invoicestatic =
new Facture($db);
78$societestatic =
new Societe($db);
84$paymentvatstatic =
new Tva($db);
89foreach ($argv as $key => $value) {
93 if (preg_match(
'/^lang=/i', $value)) {
95 $valarray = explode(
'=', $value);
96 $newlangid = $valarray[1];
97 print
'Use language '.$newlangid.
".\n";
100$outputlangs = $langs;
101if (!empty($newlangid)) {
102 if ($outputlangs->defaultlang != $newlangid) {
104 $outputlangs->setDefaultLang($newlangid);
109$outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"banks",
"members",
"compta"));
112$result = $acct->fetch(
'', $bankref);
114 print
"Failed to find bank account with ref ".$bankref.
".\n";
117 print
"Export for bank account ".$acct->ref.
" (".$acct->label.
").\n";
121$dir = DOL_DOCUMENT_ROOT.
"/core/modules/export/";
122$file =
"export_".$model.
".modules.php";
123$classname =
"Export".$model;
125 print
"No driver to export with format ".$model.
"\n";
128require_once $dir.$file;
129$objmodel =
new $classname($db);
132$dirname = $conf->bank->dir_temp;
133$filename =
'export-bank-receipts-'.$bankref.
'-'.$num.
'.'.$objmodel->extension;
135$array_fields = array(
136 'bankreceipt' => $outputlangs->transnoentitiesnoconv(
"AccountStatementShort"),
137 'bankaccount' => $outputlangs->transnoentitiesnoconv(
"BankAccount"),
138 'dateop' => $outputlangs->transnoentitiesnoconv(
"DateOperationShort"),
139 'dateval' => $outputlangs->transnoentitiesnoconv(
"DateValueShort"),
140 'type' => $outputlangs->transnoentitiesnoconv(
"Type"),
141 'description' => $outputlangs->transnoentitiesnoconv(
"Description"),
142 'thirdparty' => $outputlangs->transnoentitiesnoconv(
"Tiers"),
143 'accountelem' => $outputlangs->transnoentitiesnoconv(
"Piece"),
144 'debit' => $outputlangs->transnoentitiesnoconv(
"Debit"),
145 'credit' => $outputlangs->transnoentitiesnoconv(
"Credit"),
146 'soldbefore' => $outputlangs->transnoentitiesnoconv(
"BankBalanceBefore"),
147 'soldafter' => $outputlangs->transnoentitiesnoconv(
"BankBalanceAfter"),
148 'comment' => $outputlangs->transnoentitiesnoconv(
"Comment")
150$array_selected = array(
'bankreceipt' =>
'bankreceipt',
'bankaccount' =>
'bankaccount',
'dateop' =>
'dateop',
'dateval' =>
'dateval',
'type' =>
'type',
'description' =>
'description',
'thirdparty' =>
'thirdparty',
'accountelem' =>
'accountelem',
'debit' =>
'debit',
'credit' =>
'credit',
'soldbefore' =>
'soldbefore',
'soldafter' =>
'soldafter',
'comment' =>
'comment');
151$array_export_TypeFields = array(
'bankreceipt' =>
'Text',
'bankaccount' =>
'Text',
'dateop' =>
'Date',
'dateval' =>
'Date',
'type' =>
'Text',
'description' =>
'Text',
'thirdparty' =>
'Text',
'accountelem' =>
'Text',
'debit' =>
'Number',
'credit' =>
'Number',
'soldbefore' =>
'Number',
'soldafter' =>
'Number',
'comment' =>
'Text');
155if (!empty($num) && $num !=
"all") {
157 $arraynum = explode(
',', $num);
158 foreach ($arraynum as $val) {
159 if ($listofnum !=
"'") {
166$sql =
"SELECT b.rowid, b.dateo as do, b.datev as dv,";
167$sql .=
" b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
168$sql .=
" ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
169$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
170$sql .=
", ".MAIN_DB_PREFIX.
"bank as b";
171$sql .=
" WHERE b.fk_account = ".((int) $acct->id);
173 $sql .=
" AND b.num_releve IN (".$db->sanitize($listofnum, 1).
")";
176 $sql .=
" OR b.num_releve is null";
178$sql .=
" AND b.fk_account = ba.rowid";
179$sql .= $db->order(
"b.num_releve, b.datev, b.datec",
"ASC");
182$resql = $db->query($sql);
184 $balancebefore = array();
186 $numrows = $db->num_rows($resql);
190 print
'Open file '.$filename.
' into directory '.$dirname.
"\n";
192 $result = $objmodel->open_file($dirname.
"/".$filename, $outputlangs);
195 print
'Failed to create file '.$filename.
' into dir '.$dirname.
'.'.
"\n";
200 $objmodel->write_header($outputlangs);
203 $objmodel->write_title($array_fields, $array_selected, $outputlangs, $array_export_TypeFields);
210 while ($i < $numrows) {
215 $objp = $db->fetch_object($resql);
218 if (!isset($balancebefore[$objp->num_releve])) {
219 print
'Calculate start balance for receipt '.$objp->num_releve.
"\n";
221 $sql2 =
"SELECT sum(b.amount) as amount";
222 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
223 $sql2 .=
" WHERE b.num_releve < '".$db->escape($objp->num_releve).
"'";
224 $sql2 .=
" AND b.fk_account = ".$objp->bankid;
225 $resql2 = $db->query($sql2);
227 $obj2 = $db->fetch_object($resql2);
228 $balancebefore[$objp->num_releve] = ($obj2->amount ? $obj2->amount : 0);
235 $total = $balancebefore[$objp->num_releve];
238 $totalbefore = $total;
239 $total = $total + $objp->amount;
242 $dateop = $db->jdate($objp->do);
245 $datevalue = $db->jdate($objp->dv);
248 $numchq = ($objp->num_chq ? $objp->num_chq :
'');
252 preg_match(
'/\((.+)\)/i', $objp->label, $reg);
253 if ($reg[1] && $langs->transnoentitiesnoconv($reg[1]) != $reg[1]) {
254 $description = $langs->transnoentitiesnoconv($reg[1]);
256 $description = $objp->label;
262 $links = $acct->get_url($objp->rowid);
263 foreach ($links as $key => $val) {
264 if ($links[$key][
'type'] ==
'payment') {
265 $paymentstatic->fetch($links[$key][
'url_id']);
266 $tmparray = $paymentstatic->getBillsArray(
'');
267 if (is_array($tmparray)) {
268 foreach ($tmparray as $tmpkey => $tmpval) {
269 $invoicestatic->fetch($tmpval);
271 $accountelem .=
', ';
273 $accountelem .= $invoicestatic->ref;
276 } elseif ($links[$key][
'type'] ==
'payment_supplier') {
277 $paymentsupplierstatic->fetch($links[$key][
'url_id']);
278 $tmparray = $paymentsupplierstatic->getBillsArray(
'');
279 if (is_array($tmparray)) {
280 foreach ($tmparray as $tmpkey => $tmpval) {
281 $invoicesupplierstatic->fetch($tmpval);
283 $accountelem .=
', ';
285 $accountelem .= $invoicesupplierstatic->ref;
288 } elseif ($links[$key][
'type'] ==
'payment_sc') {
289 $paymentsocialcontributionstatic->fetch($links[$key][
'url_id']);
291 $accountelem .=
', ';
293 $accountelem .= $langs->transnoentitiesnoconv(
"SocialContribution").
' '.$paymentsocialcontributionstatic->ref;
294 } elseif ($links[$key][
'type'] ==
'payment_vat') {
295 $paymentvatstatic->fetch($links[$key][
'url_id']);
297 $accountelem .=
', ';
299 $accountelem .= $langs->transnoentitiesnoconv(
"VATPayments").
' '.$paymentvatstatic->ref;
300 } elseif ($links[$key][
'type'] ==
'banktransfert') {
301 $comment = $outputlangs->transnoentitiesnoconv(
"Transfer");
302 if ($objp->amount > 0) {
306 $banklinestatic->fetch($links[$key][
'url_id']);
307 $bankstatic->id = $banklinestatic->fk_account;
308 $bankstatic->label = $banklinestatic->bank_account_label;
309 $comment .=
' ('.$langs->transnoentitiesnoconv(
"from").
' ';
310 $comment .= $bankstatic->getNomUrl(1,
'transactions');
311 $comment .=
' '.$langs->transnoentitiesnoconv(
"toward").
' ';
312 $bankstatic->id = $objp->bankid;
313 $bankstatic->label = $objp->bankref;
314 $comment .= $bankstatic->getNomUrl(1,
'');
320 $bankstatic->id = $objp->bankid;
321 $bankstatic->label = $objp->bankref;
322 $comment .=
' ('.$langs->transnoentitiesnoconv(
"from").
' ';
323 $comment .= $bankstatic->getNomUrl(1,
'');
324 $comment .=
' '.$langs->transnoentitiesnoconv(
"toward").
' ';
325 $banklinestatic->fetch($links[$key][
'url_id']);
326 $bankstatic->id = $banklinestatic->fk_account;
327 $bankstatic->label = $banklinestatic->bank_account_label;
328 $comment .= $bankstatic->getNomUrl(1,
'transactions');
331 } elseif ($links[$key][
'type'] ==
'company') {
335 $thirdparty .=
dol_trunc($links[$key][
'label'], 24);
337 } elseif ($links[$key][
'type'] ==
'member') {
339 $accountelem .=
', ';
341 $thirdparty .= $links[$key][
'label'];
365 $debit = $credit =
'';
366 if ($objp->amount < 0) {
367 $totald = $totald + abs($objp->amount);
370 $totalc = $totalc + abs($objp->amount);
377 $rec->bankreceipt = $objp->num_releve;
378 $rec->bankaccount = $objp->banklabel;
381 $rec->type = $objp->fk_type.
' '.($objp->num_chq ? $objp->num_chq :
'');
382 $rec->description = $description;
383 $rec->thirdparty = $thirdparty;
384 $rec->accountelem = $accountelem;
385 $rec->debit = $debit;
386 $rec->credit = $credit;
387 $rec->comment = $comment;
388 $rec->soldbefore =
price2num($totalbefore);
392 $objmodel->write_record($array_selected, $rec, $outputlangs, $array_export_TypeFields);
396 print
"Found ".$numrows.
" records for receipt ".$num.
"\n";
399 $objmodel->write_footer($outputlangs);
402 $objmodel->close_file();
404 print
'File '.$filename.
' was generated into dir '.$dirname.
'.'.
"\n";
408 print
"No records found for receipt ".$num.
"\n";
Class to manage bank accounts.
Class to manage bank transaction lines.
Class to manage members of a foundation.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage payments of social contributions.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Put here description of your class.
dol_is_file($pathoffile)
Return if path is a file.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)