Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_impacc_csv_sale_purchase.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * Copyright (C) 2016 Dany De Bontridder <dany@alchimerys.be>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 /* * *
22  //!@file
23  ///Insert into the the table impacc.import_detail + status
24  *
25  */
26 require_once DIR_IMPORT_ACCOUNT."/include/class_impacc_csv.php";
27 require_once DIR_IMPORT_ACCOUNT."/include/class_impacc_verify.php";
28 
29 ///Manage one row of operation of Sale / Purchase for importing them
31 {
32 
33  ///Works by id_group_code : all the rows with the same id_code_group belong
34  ///to the same operation
35  ///The operation will be written in the right ledger
36  ///Only operation with a id_status = 0 can be transferred , -1 is in error and
37  ///1 means that it has already been transferred
38  function transform($ledger_id, $import_id)
39  {
40  throw new Exception("Not Yet Implemented");
41  }
42 
43  //-------------------------------------------------------------------
44  /// Check if Data are valid for one row
45  //!@param $row is an Impacc_Import_detail_SQL object
46  //!@param $p_format_date check for date_limit and date_payment
47  //!@param $p_thousand separator for thousands
48  //!@param $p_decimal separator for decimal
49  //-------------------------------------------------------------------
50  static function check(Impacc_Import_detail_SQL $row, $p_format_date,
51  $p_thousand, $p_decimal)
52  {
53  $and=($row->id_message=="")?"":",";
54  //-----------------
55  ///- Check VAT CODE
56  //-----------------
57  if (Impacc_Verify::check_tva($row->tva_code)==false)
58  {
59  $row->id_message=$and."CK_TVA_INVALID";
60  $and=",";
61  }
62  //-----------------
63  ///- Check Date payment
64  //-----------------
65  if ($row->id_date_payment!="")
66  {
67  $date=Impacc_Verify::check_date($row->id_date_payment,$p_format_date);
68  if ($date==false)
69  {
70  $row->id_message=$and."CK_FORMAT_DATE";
71  $and=",";
72  } else {
73  $row->id_date_payment_conv=$date;
74  }
75  }
76  //-----------------
77  ///- Check Date limit
78  //-----------------
79  if ($row->id_date_limit!="")
80  {
81  $date=Impacc_Verify::check_date($row->id_date_limit,$p_format_date);
82  if ($date==false)
83  {
84  $row->id_message=$and."CK_FORMAT_DATE";
85  $and=",";
86  } else {
87  $row->id_date_limit_conv=$date;
88  }
89  }
90 
91  //-----------------
92  ///- Check Amount VAT
93  //-----------------
94  $row->id_amount_vat_conv=Impacc_Tool::convert_amount($row->id_amount_vat,
95  $p_thousand, $p_decimal);
96  if (isNumber($row->id_amount_vat_conv)==0)
97  {
98  $and=($row->id_message=="")?"":",";
99  $row->id_message.=$and."CK_INVALID_AMOUNT";
100  }
101  //-----------------
102  ///- Check Quantity
103  //-----------------
104  $row->id_quant_conv=Impacc_Tool::convert_amount($row->id_quant,
105  $p_thousand, $p_decimal);
106  if (isNumber($row->id_quant_conv)==0)
107  {
108  $row->id_message.=$and."CK_INVALID_AMOUNT";
109  $and=",";
110  }
111  }
112 
113  function check_nb_column()
114  {
115  throw new Exception("Not Yet Implemented");
116  }
117 
118  /**
119  * @brief insert file into the table import_detail
120  */
121  function record(Impacc_Csv $p_csv, Impacc_File $p_file)
122  {
123  global $aseparator;
124  // Open the CSV file
125  $hFile=fopen($p_file->import_file->i_tmpname, "r");
126  $error=0;
127  $cn=Dossier::connect();
128  $delimiter=$aseparator[$p_csv->detail->s_delimiter-1]['label'];
129  if ($p_csv->detail->s_surround==""){
130  $p_csv->detail->s_surround='"';
131  }
132  //---- For each row ---
133  while ($row=fgetcsv($hFile, 0, $delimiter, $p_csv->detail->s_surround))
134  {
135  $nb_row=count($row);
136  $insert=new Impacc_Import_detail_SQL($cn);
137  $insert->import_id=$p_file->import_file->id;
138  if ($nb_row<9)
139  {
140  $insert->id_status=-1;
141  $insert->id_message=join($row, $delimiter);
142  }
143  else
144  {
145 
146  $insert->id_date=$row[0];
147  $insert->id_code_group=$row[1];
148  $insert->id_acc=$row[2];
149  $insert->id_pj=$row[3];
150  $insert->id_label=$row[4];
151  $insert->id_acc_second=$row[5];
152  $insert->id_quant=$row[6];
153  $insert->id_amount_novat=$row[7];
154  $insert->tva_code=$row[8];
155  $insert->id_amount_vat=$row[9];
156  $date_limit=(isset($row[10]))?$row[10]:"";
157  $insert->id_date_limit=$date_limit;
158  $date_payment=(isset($row[11]))?$row[11]:"";
159  $insert->id_date_payment=$date_payment;
160  $insert->id_nb_row=0;
161  }
162  // insert row into table with status
163  $insert->insert();
164  }
165  }
166 
167  /// Abstract cannot be called
168  // abstract function insert($a_group, $p_ledger);
169 }
static convert_amount($p_amount, $p_thousand, $p_decimal)
convert_amount($array[$i]->id_amount_novat,$this->detail->s_thousand,$this->s_decimal); ...
record(Impacc_Csv $p_csv, Impacc_File $p_file)
insert file into the table import_detail
for($i=0;$i< Database::num_row($ret);$i++) $row
global $aseparator
transform($ledger_id, $import_id)
Works by id_group_code : all the rows with the same id_code_group belong to the same operation The op...
$nb_row
Definition: search_view.php:6
static check_date($p_date, $p_format_date)
Check that the date payment has valid format . Return false or.
Manage one row of operation of Sale / Purchase for importing them.
static check(Impacc_Import_detail_SQL $row, $p_format_date, $p_thousand, $p_decimal)
Check if Data are valid for one row.
$error
global $cn
static check_tva($p_tva_code)
Check that TVA_CODE does exist , return true if exists otherwise false.