New: Working on script ot export bank receipts. Next step.
This commit is contained in:
parent
b906691fdf
commit
ff3282275d
@ -33,16 +33,6 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($argv[2]) || ! $argv[2]) {
|
|
||||||
print "Usage: $script_file bank_receipt_number (csv|tsv|excel|excel2007)\n";
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
$num=$argv[1];
|
|
||||||
$model=$argv[2];
|
|
||||||
|
|
||||||
// Recupere env dolibarr
|
|
||||||
$version='1.10';
|
|
||||||
|
|
||||||
require_once($path."../../htdocs/master.inc.php");
|
require_once($path."../../htdocs/master.inc.php");
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
|
||||||
@ -54,6 +44,24 @@ require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
|
|||||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||||
|
|
||||||
|
// Global variables
|
||||||
|
$version=DOL_VERSION;
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------- START OF YOUR CODE HERE --------------------
|
||||||
|
@set_time_limit(0);
|
||||||
|
print "***** ".$script_file." (".$version.") *****\n";
|
||||||
|
|
||||||
|
if (! isset($argv[3]) || ! $argv[3]) {
|
||||||
|
print "Usage: $script_file bank_ref bank_receipt_number (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$bankref=$argv[1];
|
||||||
|
$num=$argv[2];
|
||||||
|
$model=$argv[3];
|
||||||
|
$newlangid='en_EN'; // To force a new lang id
|
||||||
|
|
||||||
|
|
||||||
$societestatic=new Societe($db);
|
$societestatic=new Societe($db);
|
||||||
@ -66,9 +74,42 @@ $bankstatic=new Account($db);
|
|||||||
$banklinestatic=new AccountLine($db);
|
$banklinestatic=new AccountLine($db);
|
||||||
|
|
||||||
|
|
||||||
$dirname = $conf->banque->dir_temp;
|
// Parse parameters
|
||||||
$filename = 'export-bank-receipts-'.$num.'.xls';
|
foreach ($argv as $key => $value)
|
||||||
|
{
|
||||||
|
$found=false;
|
||||||
|
|
||||||
|
// Define options
|
||||||
|
if (preg_match('/^lang=/i',$value))
|
||||||
|
{
|
||||||
|
$found=true;
|
||||||
|
$valarray=explode('=',$value);
|
||||||
|
$newlangid=$valarray[1];
|
||||||
|
print 'Use language '.$newlangid.".\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$outputlangs = $langs;
|
||||||
|
if (! empty($newlangid))
|
||||||
|
{
|
||||||
|
if ($outputlangs->defaultlang != $newlangid)
|
||||||
|
{
|
||||||
|
$outputlangs = new Translate("",$conf);
|
||||||
|
$outputlangs->setDefaultLang($newlangid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$outputlangs->load("main");
|
||||||
|
$outputlangs->load("bills");
|
||||||
|
$outputlangs->load("companies");
|
||||||
|
$outputlangs->load("banks");
|
||||||
|
|
||||||
|
|
||||||
|
$acct=new Account($db);
|
||||||
|
$result=$acct->fetch('',$bankref);
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
print "Failed to find bank account with ref ".$bankref."\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// Creation de la classe d'export du model ExportXXX
|
// Creation de la classe d'export du model ExportXXX
|
||||||
$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
|
$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
|
||||||
@ -83,18 +124,44 @@ require_once $dir.$file;
|
|||||||
$objmodel = new $classname($db);
|
$objmodel = new $classname($db);
|
||||||
|
|
||||||
|
|
||||||
|
// Define target path
|
||||||
|
$dirname = $conf->banque->dir_temp;
|
||||||
|
$filename = 'export-bank-receipts-'.$bankref.'-'.$num.'.'.$objmodel->extension;
|
||||||
|
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
print 'Create file '.$filename.' into directory '.$dirname."\n";
|
print 'Create file '.$filename.' into directory '.$dirname."\n";
|
||||||
dol_mkdir($dirname);
|
dol_mkdir($dirname);
|
||||||
$result=$objmodel->open_file($dirname."/".$filename, $langs);
|
$result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
|
||||||
|
|
||||||
if ($result >= 0)
|
if ($result >= 0)
|
||||||
{
|
{
|
||||||
|
$numrows=0;
|
||||||
|
|
||||||
|
$array_fields=array(
|
||||||
|
'bankreceipt'=>$outputlangs->transnoentitiesnoconv("AccountStatementShort"), 'bankaccount'=>$outputlangs->transnoentitiesnoconv("BankAccount"),
|
||||||
|
'dateop'=>$outputlangs->transnoentitiesnoconv("DateOperationShort"),'dateval'=>$outputlangs->transnoentitiesnoconv("DateValueShort"),'type'=>$outputlangs->transnoentitiesnoconv("Type"),
|
||||||
|
'description'=>$outputlangs->transnoentitiesnoconv("Description"), 'thirdparty'=>$outputlangs->transnoentitiesnoconv("Tiers"), 'invoices'=>$outputlangs->transnoentitiesnoconv("Invoices"),
|
||||||
|
'debit'=>$outputlangs->transnoentitiesnoconv("Debit"), 'credit'=>$outputlangs->transnoentitiesnoconv("Credit"), 'sold'=>$outputlangs->transnoentitiesnoconv("Solde"), 'comment'=>$outputlangs->transnoentitiesnoconv("Comment")
|
||||||
|
);
|
||||||
|
$array_selected=array(
|
||||||
|
'bankreceipt'=>'bankreceipt', 'bankaccount'=>'bankaccount',
|
||||||
|
'dateop'=>'dateop','dateval'=>'dateval','type'=>'type',
|
||||||
|
'description'=>'description', 'thirdparty'=>'thirdparty', 'invoices'=>'invoices',
|
||||||
|
'debit'=>'debit', 'credit'=>'credit', 'sold'=>'sold', 'comment'=>'comment'
|
||||||
|
);
|
||||||
|
$array_export_TypeFields=array(
|
||||||
|
'bankreceipt'=>'Text', 'bankaccount'=>'Text',
|
||||||
|
'dateop'=>'Date','dateval'=>'Date','type'=>'Text',
|
||||||
|
'description'=>'Text', 'thirdparty'=>'Text', 'invoices'=>'Text',
|
||||||
|
'debit'=>'Number', 'credit'=>'Number', 'sold'=>'Number', 'comment'=>'Text'
|
||||||
|
);
|
||||||
|
|
||||||
// Genere en-tete
|
// Genere en-tete
|
||||||
$objmodel->write_header($outputlangs);
|
$objmodel->write_header($outputlangs);
|
||||||
|
|
||||||
// Genere ligne de titre
|
// Genere ligne de titre
|
||||||
$objmodel->write_title($this->array_export_fields[$indice],$array_selected,$outputlangs);
|
$objmodel->write_title($array_fields,$array_selected,$outputlangs);
|
||||||
|
|
||||||
|
|
||||||
// Recherche les ecritures pour le releve
|
// Recherche les ecritures pour le releve
|
||||||
@ -105,51 +172,43 @@ if ($result >= 0)
|
|||||||
$sql.= ", ".MAIN_DB_PREFIX."bank as b";
|
$sql.= ", ".MAIN_DB_PREFIX."bank as b";
|
||||||
$sql.= " WHERE b.num_releve='".$db->escape($num)."'";
|
$sql.= " WHERE b.num_releve='".$db->escape($num)."'";
|
||||||
if (!isset($num)) $sql.= " OR b.num_releve is null";
|
if (!isset($num)) $sql.= " OR b.num_releve is null";
|
||||||
$sql.= " AND b.fk_account = ".$acct->id;
|
//$sql.= " AND b.fk_account = ".$acct->id;
|
||||||
$sql.= " AND b.fk_account = ba.rowid";
|
$sql.= " AND b.fk_account = ba.rowid";
|
||||||
$sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
|
$sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
|
||||||
|
|
||||||
$resql=$db->query($sql);
|
$resql=$db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$num = $db->num_rows($resql);
|
$numrows = $db->num_rows($resql);
|
||||||
|
|
||||||
print "Lines ".$num."\n";
|
|
||||||
|
|
||||||
|
$i=0;
|
||||||
while ($i < $numrows)
|
while ($i < $numrows)
|
||||||
{
|
{
|
||||||
|
print "Lines ".$i."\n";
|
||||||
|
|
||||||
$objp = $db->fetch_object($result);
|
$objp = $db->fetch_object($result);
|
||||||
$total = $total + $objp->amount;
|
$total = $total + $objp->amount;
|
||||||
|
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
print "<tr $bc[$var]>";
|
|
||||||
|
|
||||||
// Date operation
|
// Date operation
|
||||||
print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->do),"day").'</td>';
|
$dateop=$db->jdate($objp->do);
|
||||||
|
|
||||||
// Date de valeur
|
// Date de valeur
|
||||||
print '<td align="center" valign="center" class="nowrap">';
|
$datevalue=$db->jdate($objp->dv);
|
||||||
print '<a href="releve.php?action=dvprev&num='.$num.'&account='.$acct->id.'&dvid='.$objp->rowid.'">';
|
|
||||||
print img_previous().'</a> ';
|
|
||||||
print dol_print_date($db->jdate($objp->dv),"day") .' ';
|
|
||||||
print '<a href="releve.php?action=dvnext&num='.$num.'&account='.$acct->id.'&dvid='.$objp->rowid.'">';
|
|
||||||
print img_next().'</a>';
|
|
||||||
print "</td>\n";
|
|
||||||
|
|
||||||
// Num cheque
|
// Num cheque
|
||||||
print '<td class="nowrap">'.$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:'').'</td>';
|
$numchq=($objp->num_chq?$objp->num_chq:'');
|
||||||
|
|
||||||
// Libelle
|
// Libelle
|
||||||
print '<td valign="center"><a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&account='.$acct->id.'">';
|
|
||||||
$reg=array();
|
$reg=array();
|
||||||
preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthese on tente recherche de traduction
|
preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthese on tente recherche de traduction
|
||||||
if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) print $langs->trans($reg[1]);
|
if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) $desc=$langs->trans($reg[1]);
|
||||||
else print $objp->label;
|
else $desc=$objp->label;
|
||||||
print '</a>';
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ajout les liens (societe, company...)
|
* Ajout les liens (societe, company...)
|
||||||
*/
|
*/
|
||||||
$newline=1;
|
$newline=1;
|
||||||
$links = $acct->get_url($objp->rowid);
|
$links = $acct->get_url($objp->rowid);
|
||||||
foreach($links as $key=>$val)
|
foreach($links as $key=>$val)
|
||||||
@ -246,35 +305,24 @@ if ($result >= 0)
|
|||||||
if ($objp->amount < 0)
|
if ($objp->amount < 0)
|
||||||
{
|
{
|
||||||
$totald = $totald + abs($objp->amount);
|
$totald = $totald + abs($objp->amount);
|
||||||
print '<td align="right" nowrap=\"nowrap\">'.price($objp->amount * -1)."</td><td> </td>\n";
|
$debit=price($objp->amount * -1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$totalc = $totalc + abs($objp->amount);
|
$totalc = $totalc + abs($objp->amount);
|
||||||
print "<td> </td><td align=\"right\" nowrap=\"nowrap\">".price($objp->amount)."</td>\n";
|
$credit=price($objp->amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
print "<td align=\"right\" nowrap=\"nowrap\">".price($total)."</td>\n";
|
|
||||||
|
|
||||||
if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
|
|
||||||
{
|
|
||||||
print "<td align=\"center\"><a href=\"ligne.php?rowid=$objp->rowid&account=".$acct->id."\">";
|
|
||||||
print img_edit();
|
|
||||||
print "</a></td>";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "<td align=\"center\"> </td>";
|
|
||||||
}
|
|
||||||
print "</tr>";
|
|
||||||
$i++;
|
$i++;
|
||||||
|
|
||||||
// end of special operation processing
|
// end of special operation processing
|
||||||
$objmodel->write_record($array_selected,$objp,$outputlangs,$this->array_export_TypeFields[$indice]);
|
$objmodel->write_record($array_selected,$objp,$outputlangs,$array_export_TypeFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else dol_print_error($db);
|
||||||
|
|
||||||
|
print "Found ".$numrows." records\n";
|
||||||
|
|
||||||
// Genere en-tete
|
// Genere en-tete
|
||||||
$objmodel->write_footer($outputlangs);
|
$objmodel->write_footer($outputlangs);
|
||||||
|
|||||||
@ -46,7 +46,7 @@ require_once(DOL_DOCUMENT_ROOT.'/core/lib/invoice2.lib.php');
|
|||||||
$langs->load("main");
|
$langs->load("main");
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
$version='1.24';
|
$version=DOL_VERSION;
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user