Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_impacc_csv_sale.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 require_once 'class_impacc_csv_sale_purchase.php';
20 
21 /// For Ledger of style SALE
23 {
24  //!< date_paid will introduced after insert
25  private $jr_date_paid;
26  private $suggest_pj;
27  /// Transform a group of rows to an array and set $jr_date_paid
28  /// useable by Acc_Ledger_Sold::insert
29  function adapt( $p_row)
30  {
31  bcscale(4);
32  $cn=Dossier::connect();
33 
34  // Get the code_group
35  $code_group=$p_row;
36 
37  // get all rows from this group
39  $all_row=$t->collect_objects("where import_id=$1 and id_code_group=$2",
40  array($p_row['import_id'],$p_row['id_code_group']));
41 
42  // No block due to analytic
43  global $g_parameter;
44  $g_parameter->MY_ANALYTIC="N";
45  // Save the date of payment
46  $this->jr_date_paid=$all_row[0]->id_date_payment_conv;
47 
48  // Initialise the array
49  $array=array();
50  // Suppress payment
51  $array['e_mp']=0;
52  // The first row gives all the information , the others of the group
53  // add services
54  $array['e_client']=$all_row[0]->id_acc;
55  $array['nb_item']=count($all_row);
56  $array['e_comm']=$all_row[0]->id_label;
57  // Must be transformed into DD.MM.YYYY
58  $array['e_date']=$all_row[0]->id_date_conv;
59  $array['e_ech']=$all_row[0]->id_date_limit_conv;
60  $array['e_pj']=$all_row[0]->id_pj;
61 
62  $array['mt']=microtime();
63  $array['jrn_type']='VEN';
64  $nb_row=count($all_row);
65  for ( $i=0;$i<$nb_row;$i++)
66  {
67  $array["e_march".$i]=$all_row[$i]->id_acc_second;
68  $price=$all_row[$i]->id_amount_novat_conv;
69  $quant=($all_row[$i]->id_quant_conv<>0)?$all_row[$i]->id_quant_conv:1;
70  $pricetax=$all_row[$i]->id_amount_vat_conv;
71  $price_unit=bcdiv($price,$quant);
72  $array["e_march".$i."_price"]=$price_unit;
73  $array["e_march".$i."_label"]=$all_row[$i]->id_label;
74  $array["e_march".$i."_tva_id"]=Impacc_Tool::convert_tva($all_row[$i]->tva_code); // Find code
75  $array["e_march".$i."_tva_amount"]=bcsub($pricetax,$price);
76  $array["e_quant".$i]=$quant;
77  }
78  return $array;
79  }
80  /// Transfer operation with the status correct to the
81  /// accountancy . Change the status of the row (id_status to 1) after
82  /// because it can transferred several rows in one operation
83  function insert($a_group, Acc_Ledger_Sold $p_ledger)
84  {
85  $cn=Dossier::connect();
86  $nb_group=count($a_group);
87  for ( $i=0;$i< $nb_group;$i++)
88  {
89  $array=$this->adapt($a_group[$i]);
90 
91  //Complete the array
92  $array["p_jrn"]=$p_ledger->id;
93 
94  //Receipt
95  if (trim($array['e_pj'])=="") $array["e_pj"]=$p_ledger->guess_pj();
96  $array['e_pj_suggest']=$p_ledger->guess_pj();
97 
98  // Insert
99  $p_ledger->insert($array);
100 
101  // Update this group , status = 2 , jr_id
102  // and date_payment
103  $cn->exec_sql("update impacc.import_detail set jr_id=$1 , id_status=2 where id_code_group=$2",
104  array($p_ledger->jr_id,$a_group[$i]['id_code_group']));
105  $cn->exec_sql(" update public.jrn set jr_date_paid=to_date($1,'DD.MM.YYYY') where jr_id=$2",
106  array($this->jr_date_paid,$p_ledger->jr_id));
107 
108  }
109 
110  }
111 
112 
113 
114 }
adapt($p_row)
Transform a group of rows to an array and set $jr_date_paid useable by Acc_Ledger_Sold::insert.
insert($a_group, Acc_Ledger_Sold $p_ledger)
Transfer operation with the status correct to the accountancy .
static convert_tva($p_code)
Find the correct TVA from the table impacc.parameter_tva.
$nb_row
Definition: search_view.php:6
global $g_parameter
Definition: ajax.php:27
if(isset($_POST['remove'])) $array
$jr_date_paid
< date_paid will introduced after insert
Manage one row of operation of Sale / Purchase for importing them.
For Ledger of style SALE.
global $cn