26 if (!defined(
'NOSESSION')) define(
'NOSESSION',
'1');
28 $sapi_type = php_sapi_name();
29 $script_file = basename(__FILE__);
33 if (substr($sapi_type, 0, 3) ==
'cgi') {
34 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
38 require_once $path.
"../../htdocs/master.inc.php";
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
41 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/paymentsocialcontribution.class.php';
54 $version = DOL_VERSION;
63 dol_syslog($script_file.
" launched with arg ".join(
',', $argv));
65 if (!isset($argv[3]) || !$argv[3]) {
66 print "Usage: ".$script_file.
" bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
74 $invoicestatic =
new Facture($db);
76 $societestatic =
new Societe($db);
82 $paymentvatstatic =
new Tva($db);
87 foreach ($argv as $key => $value) {
91 if (preg_match(
'/^lang=/i', $value)) {
93 $valarray = explode(
'=', $value);
94 $newlangid = $valarray[1];
95 print 'Use language '.$newlangid.
".\n";
98 $outputlangs = $langs;
99 if (!empty($newlangid)) {
100 if ($outputlangs->defaultlang != $newlangid) {
102 $outputlangs->setDefaultLang($newlangid);
107 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"banks",
"members",
"compta"));
110 $result = $acct->fetch(
'', $bankref);
112 print "Failed to find bank account with ref ".$bankref.
".\n";
115 print "Export for bank account ".$acct->ref.
" (".$acct->label.
").\n";
119 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/export/";
120 $file =
"export_".$model.
".modules.php";
121 $classname =
"Export".$model;
123 print "No driver to export with format ".$model.
"\n";
126 require_once $dir.$file;
127 $objmodel =
new $classname($db);
130 $dirname = $conf->bank->dir_temp;
131 $filename =
'export-bank-receipts-'.$bankref.
'-'.$num.
'.'.$objmodel->extension;
133 $array_fields = array(
134 'bankreceipt' => $outputlangs->transnoentitiesnoconv(
"AccountStatementShort"),
135 'bankaccount' => $outputlangs->transnoentitiesnoconv(
"BankAccount"),
136 'dateop' => $outputlangs->transnoentitiesnoconv(
"DateOperationShort"),
137 'dateval' => $outputlangs->transnoentitiesnoconv(
"DateValueShort"),
138 'type' => $outputlangs->transnoentitiesnoconv(
"Type"),
139 'description' => $outputlangs->transnoentitiesnoconv(
"Description"),
140 'thirdparty' => $outputlangs->transnoentitiesnoconv(
"Tiers"),
141 'accountelem' => $outputlangs->transnoentitiesnoconv(
"Piece"),
142 'debit' => $outputlangs->transnoentitiesnoconv(
"Debit"),
143 'credit' => $outputlangs->transnoentitiesnoconv(
"Credit"),
144 'soldbefore' => $outputlangs->transnoentitiesnoconv(
"BankBalanceBefore"),
145 'soldafter' => $outputlangs->transnoentitiesnoconv(
"BankBalanceAfter"),
146 'comment' => $outputlangs->transnoentitiesnoconv(
"Comment")
148 $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');
149 $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');
153 if (!empty($num) && $num !=
"all") {
155 $arraynum = explode(
',', $num);
156 foreach ($arraynum as $val) {
157 if ($listofnum !=
"'")
163 $sql =
"SELECT b.rowid, b.dateo as do, b.datev as dv,";
164 $sql .=
" b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
165 $sql .=
" ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
166 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
167 $sql .=
", ".MAIN_DB_PREFIX.
"bank as b";
168 $sql .=
" WHERE b.fk_account = ".$acct->id;
170 $sql .=
" AND b.num_releve IN (".$listofnum.
")";
172 $sql .=
" OR b.num_releve is null";
173 $sql .=
" AND b.fk_account = ba.rowid";
174 $sql .= $db->order(
"b.num_releve, b.datev, b.datec",
"ASC");
177 $resql = $db->query($sql);
179 $balancebefore = array();
181 $numrows = $db->num_rows(
$resql);
185 print 'Open file '.$filename.
' into directory '.$dirname.
"\n";
187 $result = $objmodel->open_file($dirname.
"/".$filename, $outputlangs);
190 print 'Failed to create file '.$filename.
' into dir '.$dirname.
'.'.
"\n";
195 $objmodel->write_header($outputlangs);
198 $objmodel->write_title($array_fields, $array_selected, $outputlangs, $array_export_TypeFields);
202 while ($i < $numrows) {
207 $objp = $db->fetch_object(
$resql);
210 if (!isset($balancebefore[$objp->num_releve])) {
211 print 'Calculate start balance for receipt '.$objp->num_releve.
"\n";
213 $sql2 =
"SELECT sum(b.amount) as amount";
214 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
215 $sql2 .=
" WHERE b.num_releve < '".$db->escape($objp->num_releve).
"'";
216 $sql2 .=
" AND b.fk_account = ".$objp->bankid;
217 $resql2 = $db->query($sql2);
219 $obj2 = $db->fetch_object($resql2);
220 $balancebefore[$objp->num_releve] = ($obj2->amount ? $obj2->amount : 0);
227 $total = $balancebefore[$objp->num_releve];
230 $totalbefore = $total;
231 $total = $total + $objp->amount;
234 $dateop = $db->jdate($objp->do);
237 $datevalue = $db->jdate($objp->dv);
240 $numchq = ($objp->num_chq ? $objp->num_chq :
'');
244 preg_match(
'/\((.+)\)/i', $objp->label, $reg);
245 if ($reg[1] && $langs->transnoentitiesnoconv($reg[1]) != $reg[1])
246 $description = $langs->transnoentitiesnoconv($reg[1]);
247 else $description = $objp->label;
252 $links = $acct->get_url($objp->rowid);
253 foreach ($links as $key => $val) {
254 if ($links[$key][
'type'] ==
'payment') {
255 $paymentstatic->fetch($links[$key][
'url_id']);
256 $tmparray = $paymentstatic->getBillsArray(
'');
257 if (is_array($tmparray)) {
258 foreach ($tmparray as $tmpkey => $tmpval) {
259 $invoicestatic->fetch($tmpval);
261 $accountelem .=
', ';
263 $accountelem .= $invoicestatic->ref;
266 } elseif ($links[$key][
'type'] ==
'payment_supplier') {
267 $paymentsupplierstatic->fetch($links[$key][
'url_id']);
268 $tmparray = $paymentsupplierstatic->getBillsArray(
'');
269 if (is_array($tmparray)) {
270 foreach ($tmparray as $tmpkey => $tmpval) {
271 $invoicesupplierstatic->fetch($tmpval);
273 $accountelem .=
', ';
275 $accountelem .= $invoicesupplierstatic->ref;
278 } elseif ($links[$key][
'type'] ==
'payment_sc') {
279 $paymentsocialcontributionstatic->fetch($links[$key][
'url_id']);
281 $accountelem .=
', ';
283 $accountelem .= $langs->transnoentitiesnoconv(
"SocialContribution").
' '.$paymentsocialcontributionstatic->ref;
284 } elseif ($links[$key][
'type'] ==
'payment_vat') {
285 $paymentvatstatic->fetch($links[$key][
'url_id']);
287 $accountelem .=
', ';
289 $accountelem .= $langs->transnoentitiesnoconv(
"VATPayments").
' '.$paymentvatstatic->ref;
290 } elseif ($links[$key][
'type'] ==
'banktransfert') {
291 $comment = $outputlangs->transnoentitiesnoconv(
"Transfer");
292 if ($objp->amount > 0) {
296 $banklinestatic->fetch($links[$key][
'url_id']);
297 $bankstatic->id = $banklinestatic->fk_account;
298 $bankstatic->label = $banklinestatic->bank_account_label;
299 $comment .=
' ('.$langs->transnoentitiesnoconv(
"from").
' ';
300 $comment .= $bankstatic->getNomUrl(1,
'transactions');
301 $comment .=
' '.$langs->transnoentitiesnoconv(
"toward").
' ';
302 $bankstatic->id = $objp->bankid;
303 $bankstatic->label = $objp->bankref;
304 $comment .= $bankstatic->getNomUrl(1,
'');
310 $bankstatic->id = $objp->bankid;
311 $bankstatic->label = $objp->bankref;
312 $comment .=
' ('.$langs->transnoentitiesnoconv(
"from").
' ';
313 $comment .= $bankstatic->getNomUrl(1,
'');
314 $comment .=
' '.$langs->transnoentitiesnoconv(
"toward").
' ';
315 $banklinestatic->fetch($links[$key][
'url_id']);
316 $bankstatic->id = $banklinestatic->fk_account;
317 $bankstatic->label = $banklinestatic->bank_account_label;
318 $comment .= $bankstatic->getNomUrl(1,
'transactions');
321 } elseif ($links[$key][
'type'] ==
'company') {
325 $thirdparty .=
dol_trunc($links[$key][
'label'], 24);
327 } elseif ($links[$key][
'type'] ==
'member') {
329 $accountelem .=
', ';
331 $thirdparty .= $links[$key][
'label'];
355 $debit = $credit =
'';
356 if ($objp->amount < 0) {
357 $totald = $totald + abs($objp->amount);
360 $totalc = $totalc + abs($objp->amount);
366 $rec =
new stdClass();
367 $rec->bankreceipt = $objp->num_releve;
368 $rec->bankaccount = $objp->banklabel;
371 $rec->type = $objp->fk_type.
' '.($objp->num_chq ? $objp->num_chq :
'');
372 $rec->description = $description;
373 $rec->thirdparty = $thirdparty;
374 $rec->accountelem = $accountelem;
375 $rec->debit = $debit;
376 $rec->credit = $credit;
377 $rec->comment = $comment;
378 $rec->soldbefore =
price2num($totalbefore);
382 $objmodel->write_record($array_selected, $rec, $outputlangs, $array_export_TypeFields);
386 print "Found ".$numrows.
" records for receipt ".$num.
"\n";
389 $objmodel->write_footer($outputlangs);
392 $objmodel->close_file();
394 print 'File '.$filename.
' was generated into dir '.$dirname.
'.'.
"\n";
398 print "No records found for receipt ".$num.
"\n";
Class to manage payments of social contributions.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
Class to manage bank transaction lines.
Class to manage suppliers invoices.
Class to manage bank accounts.
Put here description of your class.
Class to manage third parties objects (customers, suppliers, prospects...)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage payments of customer invoices.
Class to manage members of a foundation.
Class to manage translations.
dol_is_file($pathoffile)
Return if path is a file.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
Class to manage invoices.
Class to manage payments for supplier invoices.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)