[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpcompta-dev] r312 - in trunk: . import_doli import_doli/doc import_do
From: |
phpcompta-dev |
Subject: |
[Phpcompta-dev] r312 - in trunk: . import_doli import_doli/doc import_doli/include import_doli/include/template |
Date: |
Fri, 23 Mar 2012 22:53:16 +0100 (CET) |
Author: danydb
Date: 2012-03-23 22:53:15 +0100 (Fri, 23 Mar 2012)
New Revision: 312
Added:
trunk/import_doli/
trunk/import_doli/README.txt
trunk/import_doli/doc/
trunk/import_doli/doc/import_doli.odt
trunk/import_doli/include/
trunk/import_doli/include/class_import_card.php
trunk/import_doli/include/template/
trunk/import_doli/include/template/input_file.php
trunk/import_doli/include/template/test_file.php
trunk/import_doli/index.php
Log:
Plugin d'import de donn?\195?\169es de DOLIBARR
Added: trunk/import_doli/README.txt
===================================================================
--- trunk/import_doli/README.txt (rev 0)
+++ trunk/import_doli/README.txt 2012-03-23 21:53:15 UTC (rev 312)
@@ -0,0 +1 @@
+Skeleton of a plugin. It contains the structure and example.
Added: trunk/import_doli/doc/import_doli.odt
===================================================================
(Binary files differ)
Property changes on: trunk/import_doli/doc/import_doli.odt
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/import_doli/include/class_import_card.php
===================================================================
--- trunk/import_doli/include/class_import_card.php
(rev 0)
+++ trunk/import_doli/include/class_import_card.php 2012-03-23 21:53:15 UTC
(rev 312)
@@ -0,0 +1,243 @@
+<?php
+
+/*
+ * This file is part of PhpCompta.
+ *
+ * PhpCompta 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpCompta 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 PhpCompta; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+/* $Revision$ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/* !\file
+ * \brief Manage import
+ */
+
+class Import_Card
+{
+
+ /**
+ * @brief for the form we have here all the hidden variables
+ * @return html string with the hidden dossier, plugin_code,action(sa)
+ */
+ static function hidden()
+ {
+ $r = HtmlInput::extension() . Dossier::hidden();
+ return $r;
+ }
+
+ /**
+ * @brief show the first screen, you must here enter the date format
+ * the file, the card category,
+ * @return html string
+ */
+ static function new_import()
+ {
+ global $cn;
+ ob_start();
+ $hidden = self::hidden() . HtmlInput::hidden('sa', 'test');
+ $delimiter = new IText('rdelimiter');
+ $delimiter->size = 1;
+ $delimiter->value = ',';
+
+ $fd = new ISelect('rfichedef');
+ $fd->value = $cn->make_array('select fd_id,fd_label from
fiche_def order by 2');
+ $file = new IFile('csv_file');
+ $encodage = new ICheckBox('encodage');
+ $encodage->selected = true;
+
+ require_once('template/input_file.php');
+ $r = ob_get_contents();
+ ob_clean();
+ echo $r;
+ }
+
+ /**
+ * Test the CSV file, show the choosed delimiter, the CSV parsed,
+ * and replace column header by attribute
+ * @return 0 ok, -1 error
+ */
+ static function test_import()
+ {
+ global $cn;
+ $hidden = self::hidden() . HtmlInput::hidden('sa', 'record');
+
+ if (trim($_FILES['csv_file']['name']) == '')
+ {
+ alert('Pas de fichier donné');
+ return -1;
+ }
+ $filename = tempnam($_ENV['TMP'], 'upload_');
+ move_uploaded_file($_FILES["csv_file"]["tmp_name"], $filename);
+
+ $file_cat = $cn->get_value('select fd_label from fiche_def
where fd_id=$1', array($_POST['rfichedef']));
+ $encoding = (isset($_REQUEST['encodage'])) ? 'Unicode' :
'latin1';
+ require_once('template/test_file.php');
+ return 0;
+ }
+
+ /**
+ * @brief record all rows
+ * @param
+ * @return
+ * @note
+ * @see
+ @code
+ array
+ 'plugin_code' => string 'IMPCARD' (length=7)
+ 'gDossier' => string '30' (length=2)
+ 'sa' => string 'record' (length=6)
+ 'rfichedef' => string '17' (length=2)
+ 'rdelimiter' => string ',' (length=1)
+ 'encodage' => string '' (length=0)
+ 'record_import' => string 'Valider' (length=7)
+ 'head_col' =>
+ array
+ 0 => string '15' (length=2)
+ 1 => string '14' (length=2)
+ 2 => string '-1' (length=2)
+ 3 => string '-1' (length=2)
+ 4 => string '-1' (length=2)
+ 5 => string '-1' (length=2)
+
+ @endcode
+ */
+ static function record_import()
+ {
+
+ global $cn, $g_failed, $g_succeed;
+ extract($_POST);
+ $fd = fopen($filename, 'r');
+ /*
+ * Check the column
+ */
+ $valid_col = 0;
+ $valid_name = 0;
+ $duplicate = 0;
+ $valid_qcode = 0;
+ $valid_accounting = 0;
+ for ($i = 0; $i < count($head_col); $i++)
+ {
+ if ($head_col[$i] != -1)
+ $valid_col++;
+ if ($head_col[$i] == 1)
+ $valid_name = 1;
+ if ($head_col[$i] == ATTR_DEF_QUICKCODE)
+ $valid_qcode = 1;
+ if ($head_col[$i] == ATTR_DEF_ACCOUNT)
+ $valid_accounting = 1;
+
+ for ($e = $i + 1; $e < count($head_col); $e++)
+ if ($head_col[$i] == $head_col[$e] &&
$head_col[$e] != -1)
+ $duplicate++;
+ }
+
+ if ($valid_col == 0)
+ {
+ alert("Aucune colonne n'est définie");
+ return -1;
+ }
+ if ($valid_name == 0)
+ {
+ alert("Les fiches doivent avoir au minimum un nom");
+ return -1;
+ }
+ if ($duplicate != 0)
+ {
+ alert('Vous avez défini plusieurs fois la même
colonne');
+ return -1;
+ }
+
+
+ /*
+ * read the file and record card
+ */
+
+ $row_count = 0;
+
+ echo '<table>';
+
+ ob_start();
+ while (($row = fgetcsv($fd, 0, $_POST['rdelimiter'],
$_POST['rsurround'])) !== false)
+ {
+ $fiche = new Fiche($cn);
+ $array = array();
+ $row_count++;
+ echo '<tr style="border:solid 1px black">';
+ echo td($row_count);
+ $count_col = count($row);
+ $col_count = 0;
+ for ($i = 0; $i < $count_col; $i++)
+ {
+ if ($head_col[$i] == -1)
+ continue;
+
+ $header[$col_count] = $head_col[$i];
+ $col_count++;
+
+ echo td($row[$i]);
+ $attr = sprintf('av_text%d', $head_col[$i]);
+ $array[$attr] = $row[$i];
+ }
+ /*
+ * If no quick code is given we compute it ourself
+ */
+ if ($valid_qcode == 0)
+ {
+ $attr = sprintf('av_text%d',
ATTR_DEF_QUICKCODE);
+ $array[$attr] = 'FID';
+ }
+ /*
+ * Force the creating of an accounting
+ */
+ if ($valid_accounting == 0)
+ {
+ $attr = sprintf('av_text%d', ATTR_DEF_ACCOUNT);
+ $array[$attr] = '';
+ }
+ try
+ {
+ $fiche->insert($rfichedef, $array);
+ echo td($g_succeed);
+ }
+ catch (Exception $e)
+ {
+ echo td($g_failed);
+ echo td($e->getMessage());
+ }
+ echo '</tr>';
+ }
+ $table_content = ob_get_contents();
+ ob_clean();
+ echo '<tr>';
+ echo th('');
+ for ($e = 0; $e < count($header); $e++)
+ {
+ $name = $cn->get_value('select ad_text from attr_def
where ad_id=$1', array($header[$e]));
+ echo th($name);
+ }
+ echo '</tr>';
+ echo $table_content;
+
+ echo '</table>';
+ $name = $cn->get_value('select fd_label from fiche_def where
fd_id=$1', array($rfichedef));
+ $cn->get_value('select comptaproc.fiche_attribut_synchro($1)',
array($rfichedef));
+ echo '<span class="notice">';
+ echo $row_count . ' fiches sont insérées dans la catégorie ' .
$name;
+ echo '</span>';
+ return 0;
+ }
+
+}
\ No newline at end of file
Added: trunk/import_doli/include/template/input_file.php
===================================================================
--- trunk/import_doli/include/template/input_file.php
(rev 0)
+++ trunk/import_doli/include/template/input_file.php 2012-03-23 21:53:15 UTC
(rev 312)
@@ -0,0 +1,33 @@
+<h2>
+<?php
+echo _('Importation de données');
+?>
+</h2>
+
+<p>Pour importer des données, c'est-à-dire transformer des fichiers CSV
(Valeur séparé par des virgules) en des fiches. Vous devez choisir, un fichier
et donner une catégorie de fiche existante. Ensuite, il suffit d'indiquer
quelles colonnes correspondent à quelle attribut.
+</p>
+<p>
+ Par défaut, correspond à un export CSV depuis Calc (OpenOffice.org ou
libreoffice);
+</p>
+<form method="POST" enctype="multipart/form-data">
+<?=$hidden?>
+<table>
+<tr>
+<td>Délimiteur </td><TD> <? echo $delimiter->input()?></td>
+</tr>
+<tr>
+<td>Fichier à charger</td><TD> <? echo $file->input()?></td>
+</tr>
+<tr>
+<td>Catégorie de fiche</td><TD> <? echo $fd->input();?></td>
+</tr>
+<tr>
+<td>Encodage unicode</td><TD> <? echo $encodage->input()?></td>
+</tr>
+<tr>
+<td> Texte entouré du signe </td><TD><input type="text" name="rsurround"
value='"' size="1"></td>
+</tr>
+</table>
+<? echo HtmlInput::submit('test_import','Valider');?>
+
+</form>
Added: trunk/import_doli/include/template/test_file.php
===================================================================
--- trunk/import_doli/include/template/test_file.php
(rev 0)
+++ trunk/import_doli/include/template/test_file.php 2012-03-23 21:53:15 UTC
(rev 312)
@@ -0,0 +1,91 @@
+
+<h2>
+<?php
+echo _('Importation de données');
+?>
+</h2>
+
+<p>Pour importer des données, c'est-à-dire transformer des fichiers CSV
(Valeur séparé par des virgules) en des fiches. Vous devez choisir, un fichier
et donner une catégorie de fiche existante. Ensuite, il suffit d'indiquer
quelles colonnes correspondent à quelle attribut.
+</p>
+
+<form method="POST" >
+<?=$hidden?>
+<table>
+<tr>
+<td>Délimiteur </td>
+<td> <? echo $_POST['rdelimiter']?></td>
+</tr>
+<tr>
+<td>Fichier à charger</td><td> <? echo $_FILES['csv_file']['name']?></td>
+</tr>
+<tr>
+<td>Catégorie de fiche</td><td> <? echo $file_cat;?></td>
+</tr>
+<tr>
+<td>Encodage </td><td> <? echo $encoding?></td>
+</tr>
+<tr>
+<td>Texte entouré par</td><td> <? echo $_POST['rsurround'];?></td>
+</tr>
+</table>
+<?
+foreach (array('rfichedef','rdelimiter','encodage') as $e)
+{
+ if ( isset($_POST[$e])) echo HtmlInput::hidden($e,$_POST[$e]);
+}
+echo HtmlInput::hidden('filename',$filename);
+
+ echo HtmlInput::submit('record_import','Valider');
+?>
+<input type="hidden" name="rsurround" value='<?=$_POST['rsurround']?>'>
+
+
+
+<?
+ global $cn;
+ ob_start();
+ /**
+ * Open the file and parse it
+ */
+$fcard=fopen($filename,'r');
+$row_count=0;
+$max=0;
+while (($row=fgetcsv($fcard,0,$_POST['rdelimiter'],$_POST['rsurround'])) !==
false)
+ {
+ $row_count++;
+ echo '<tr style="border:solid 1px black">';
+ echo td($row_count);
+ $count_col=count($row);
+ $max=($count_col>$max)?$count_col:$max;
+ for ($i=0;$i<$count_col;$i++)
+ {
+ echo td($row[$i],'style="border:solid 1px black"');
+ }
+ echo '</tr>';
+ }
+$table=ob_get_contents();
+ob_clean();
+
+
+echo '<table style="border:solid 1px black;width:100%">
+<tr>';
+
+/**
+ *create widget column header
+ */
+$header=new ISelect('head_col[]');
+
+$sql=sprintf('select ad_id,ad_text from jnt_fic_attr join attr_def
using(ad_id) where fd_id=%d order by ad_text ',$_POST['rfichedef']);
+$header->value=$cn->make_array($sql);
+$header->value[]=array('value'=>-1,'label'=>'-- Non Utilisé --');
+$header->selected=-1;
+echo th('Numéro de ligne');
+for ($i=0;$i<$max;$i++)
+ {
+ echo '<th>'.$header->input().'</th>';
+ }
+echo '</tr>';
+echo $table;
+echo '</table>';
+echo '</form>';
+?>
\ No newline at end of file
Added: trunk/import_doli/index.php
===================================================================
--- trunk/import_doli/index.php (rev 0)
+++ trunk/import_doli/index.php 2012-03-23 21:53:15 UTC (rev 312)
@@ -0,0 +1,54 @@
+<?php
+/*
+ * This file is part of PhpCompta.
+ *
+ * PhpCompta 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpCompta 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 PhpCompta; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+/* $Revision$ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief main file for importing card
+ */
+
+/*
+ * load javascript
+ */
+require_once('include/class_import_card.php');
+global $cn;
+echo '<div style="float:right"><a class="mtitle" style="font-size:140%"
href="http://wiki.phpcompta.eu/doku.php?id=importation_de_fiche"
target="_blank">Aide</a>'.
+'<span style="font-size:0.8em;color:red;display:inline">vers:SVNINFO</span>'.
+'</div>';
+$cn=new Database(dossier::id());
+if ( ! isset($_REQUEST['sa']))
+ {
+ Import_Card::new_import();
+ exit();
+ }
+
+if ( $_REQUEST['sa']=='test')
+ {
+ if (Import_Card::test_import() == 0 ) exit();
+ Import_Card::new_import();
+ exit();
+
+ }
+
+if($_REQUEST['sa'] == 'record')
+ {
+ if (Import_Card::record_import() ==0 ) exit();
+ Import_Card::new_import();
+ }
\ No newline at end of file
---
PhpCompta est un logiciel de comptabilité libre en ligne (full web)
Projet opensource http://www.phpcompta.eu
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpcompta-dev] r312 - in trunk: . import_doli import_doli/doc import_doli/include import_doli/include/template,
phpcompta-dev <=