';
diff --git a/include/class/operation_predef_mtable.class.php b/include/class/operation_predef_mtable.class.php
new file mode 100644
index 000000000..3febada5e
--- /dev/null
+++ b/include/class/operation_predef_mtable.class.php
@@ -0,0 +1,120 @@
+set_property_visible("od_id",false);
+ $this->set_property_visible("od_direct",false);
+ $this->set_property_visible("od_item",false);
+ $this->set_col_label("jrn_def_id",_("Journal"));
+ $this->set_col_label("od_name",_("Nom"));
+ $this->set_col_label("od_jrn_type",_("Type de journal"));
+ $this->set_col_label("od_description",_("Description"));
+
+ $aLedger=$p_table->cn->make_array("select jrn_def_id,jrn_def_name from jrn_def order by jrn_def_name asc");
+
+ $this->set_sort_column("jrn_def_id");
+ $this->set_order(array("jrn_def_id","od_name","od_description","od_jrn_type"));
+ $this->set_col_type("jrn_def_id","select",$aLedger);
+
+ $this->set_callback("ajax_misc.php");
+ $this->set_property_updatable("jrn_def_id",false);
+ $this->set_property_updatable("od_jrn_type",false);
+ $this->pre_operation=null;
+
+ }
+
+ /**
+ * Display the form
+ * @throws Exception
+ */
+ function input()
+ {
+ $obj=$this->get_table();
+ $this->pre_operation = new Pre_operation($obj->cn);
+ $this->pre_operation->set_od_id($obj->get("od_id"));
+ $this->pre_operation->display();
+ }
+
+ /**
+ * Get values from the request
+ * - table is the sql table
+ * - ctl_id is the dialog box id
+ * - p_id = predef_op.od_id
+ *
+ * @code
+ * json = {"table":"public.op_predef",
+ "ctl_id":"dtr",
+ "ac":"COMPTA/ADV/PREDOP",
+ "op":"save_predf",
+ "gDossier":["28", "28"],
+ "p_id":"15",
+ "action":"save",
+ "ctl":"tbl5f6a1d09035f2",
+ "nb_item":"10",
+ "e_client":"",
+ "p_jrn":"2",
+ "e_march0":"MARCHA",
+ "e_march0_price":"102.0000",
+ "e_quant0":"1.0000",
+ "htva_march0":"0",
+ "e_march0_tva_id":"4",
+ "bt_e_march0_tva_id":"+TVA+",
+ "e_march0_tva_amount":"0.0000",
+ "tva_march0":"0","tvac_march0":"0",
+ "jrn_type":"VEN",
+ "5f6a1d0b23242_ledger":"O","
+ 5f6a1d0b23242":"1",
+ "update":"OK",
+ "5f6a1d5b70997_ledger":"O",
+ "5f6a1d5b70997":"1"}
+ * @endcode
+ */
+ function from_request()
+ {
+ $http=new HttpInput();
+ $obj=$this->get_table();
+ $this->pre_operation=new Pre_operation($obj->cn);
+ $this->pre_operation->get_post();
+ $this->pre_operation->set_od_id($http->post("p_id","number"));
+ }
+
+ function save()
+ {
+ $this->pre_operation->save();
+
+
+ }
+}
\ No newline at end of file
diff --git a/include/class/pre_op_ach.class.php b/include/class/pre_op_ach.class.php
index 722c9deed..5b5198abc 100644
--- a/include/class/pre_op_ach.class.php
+++ b/include/class/pre_op_ach.class.php
@@ -29,97 +29,86 @@ require_once NOALYSS_INCLUDE.'/class/pre_operation.class.php';
*/
class Pre_op_ach extends Pre_operation_detail
{
- var $op;
- function __construct($cn,$p_id=0)
+ function __construct($cn)
{
- parent::__construct($cn,$p_id);
-
- $this->operation->od_direct='f';
+ parent::__construct($cn);
}
function get_post()
{
- parent::get_post();
- $http=new HttpInput();
- $this->operation->od_direct='f';
+ $http = new \HttpInput();
+ $nb = $http->post("nb_item", "number");
$this->e_client=$http->post('e_client');
- for ($i=0;$i<$this->operation->nb_item;$i++)
- {
- $march="e_march".$i;
- $this->$march=$http->post('e_march'.$i);
- $this->{"e_march".$i."_price"}=$http->post('e_march'.$i."_price","string",0);
- $this->{"e_march".$i."_price"}=$http->post('e_march'.$i."_price","string",0);
- $this->{"e_march".$i."_tva_id"}=$http->post('e_march'.$i."_tva_id","string",0);
- $this->{"e_march".$i."_tva_amount"}=$http->post('e_march'.$i."_tva_amount","string",0);
- $this->{"e_march".$i."_label"}=$http->post('e_march'.$i."_label","string",NULL);
- $this->{"e_quant".$i}=$http->post('e_quant'.$i);
-
+ for ($i = 0; $i < $nb; $i++) {
+ $march = "e_march" . $i;
+ $http->set_empty("");
+ $this->$march = $http->post('e_march' . $i);
+ $this->{"e_march" . $i . "_tva_id"} = $http->post('e_march' . $i . "_tva_id", "string", 0);
+ $this->{"e_march" . $i . "_tva_id"} = $http->post('e_march' . $i . "_tva_id", "string", "0");
+ $this->{"e_march" . $i . "_label"} = $http->post('e_march' . $i . "_label", "string", "");
+ $http->set_empty(0);
+ $this->{"e_march" . $i . "_price"} = $http->post('e_march' . $i . "_price","number");
+ $this->{"e_march" . $i . "_tva_amount"} = $http->post('e_march' . $i . "_tva_amount", "string", "0");
+ $this->{"e_quant" . $i} = $http->post('e_quant' . $i, "number");
}
}
-
/*!
* \brief save the detail and op in the database
*
*/
- function save()
+ function save($p_od_id,$p_nb_item)
{
try
{
- $this->db->start();
- if ($this->operation->save() == false )
- return;
// save the client
$sql=sprintf('insert into op_predef_detail (od_id,opd_poste,opd_debit)'.
- ' values '.
- "(%d,'%s','%s')",
- $this->operation->od_id,
- $this->e_client,
- "f");
+ ' values '.
+ "(%d,'%s','%s')",
+ $p_od_id,
+ $this->e_client,
+ "f");
$this->db->exec_sql($sql);
- // save the selling
- for ($i=0;$i<$this->operation->nb_item;$i++)
+
+ for ($i=0;$i<$p_nb_item;$i++)
{
if ( strlen(trim($this->{"e_march".$i}))=="") continue;
$sql= 'insert into op_predef_detail (opd_poste,'
- . 'opd_amount,'
- . 'opd_tva_id,'
- . 'opd_quantity,'
- . 'opd_debit,'
- . 'od_id ,'
- . 'opd_tva_amount,'
- . 'opd_comment'.
- ')'.
- ' values ($1,$2,$3,$4,$5,$6,$7,$8)';
+ . 'opd_amount,'
+ . 'opd_tva_id,'
+ . 'opd_quantity,'
+ . 'opd_debit,'
+ . 'od_id ,'
+ . 'opd_tva_amount,'
+ . 'opd_comment'.
+ ')'.
+ ' values ($1,$2,$3,$4,$5,$6,$7,$8)';
$this->db->exec_sql($sql,
- array($this->{"e_march".$i},
- $this->{"e_march".$i."_price"},
- $this->{"e_march".$i."_tva_id"},
- $this->{"e_quant".$i},
- 't',
- $this->operation->od_id,
- $this->{"e_march".$i."_tva_amount"},
- $this->{"e_march".$i."_label"},
- ));
+ array($this->{"e_march".$i},
+ $this->{"e_march".$i."_price"},
+ $this->{"e_march".$i."_tva_id"},
+ $this->{"e_quant".$i},
+ 't',
+ $p_od_id,
+ $this->{"e_march".$i."_tva_amount"},
+ $this->{"e_march".$i."_label"},
+ ));
}
}
catch (Exception $e)
{
- record_log($e);
- echo ($e->getMessage());
- $this->db->rollback();
+ record_log("PREOPACH01".$e->getMessage().$e->getTraceAsString());
+ throw $e;
}
- $this->db->commit();
}
/*!\brief compute an array accordingly with the FormVenView function
* @return an array for filling the form
*/
- function compute_array()
+ function compute_array($p_od_id)
{
$count=0;
- $a_op=$this->operation->load();
- $array=$this->operation->compute_array($a_op);
- $p_array=$this->load();
- if ( empty ($p_array)) return array();
+ $array=array();
+ $p_array=$this->load($p_od_id);
+ if (empty($p_array)) return array();
foreach ($p_array as $row)
{
if ( $row['opd_debit']=='f')
@@ -128,19 +117,20 @@ class Pre_op_ach extends Pre_operation_detail
}
else
{
- if ( trim($row['opd_poste']) !="" )
+ if ( trim($row['opd_poste']) != "")
{
$array+=array("e_march".$count=>$row['opd_poste'],
- "e_march".$count."_price"=>$row['opd_amount'],
- "e_march".$count."_tva_id"=>$row['opd_tva_id'],
- "e_march".$count."_tva_amount"=>$row['opd_tva_amount'],
- "e_quant".$count=>$row['opd_quantity']
- );
+ "e_march".$count."_price"=>$row['opd_amount'],
+ "e_march".$count."_tva_id"=>$row['opd_tva_id'],
+ "e_quant".$count=>$row['opd_quantity'],
+ "e_march".$count."_label"=>$row['opd_comment'],
+ "e_march".$count."_tva_amount"=>$row['opd_tva_amount'],
+ );
$count++;
}
}
- $array['nb_item']=$count;
}
+
return $array;
}
/**
@@ -148,263 +138,260 @@ class Pre_op_ach extends Pre_operation_detail
* load the data from the database and return an array
* \return an array
*/
- function load()
+ function load($p_od_id)
{
$sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,".
- " opd_quantity,opd_tva_amount from op_predef_detail where od_id=".$this->operation->od_id.
- " order by opd_id";
- $res=$this->db->exec_sql($sql);
+ " opd_quantity , opd_comment,opd_tva_amount from op_predef_detail where od_id= $1 ".
+ " order by opd_id";
+ $res=$this->db->exec_sql($sql,[$p_od_id]);
$array=Database::fetch_all($res);
return $array;
}
- function set_od_id($p_id)
- {
- $this->operation->od_id=$p_id;
- }
+
function display($p_array)
{
require_once NOALYSS_INCLUDE.'/class/acc_ledger_purchase.class.php';
global $g_parameter,$g_user;
- extract($p_array, EXTR_SKIP);
- $ledger=new Acc_Ledger_Purchase($this->db,$this->jrn_def_id);
- if ( $p_array != null ) extract($p_array, EXTR_SKIP);
+ $ledger=new Acc_Ledger_Purchase($this->db,$p_array['p_jrn']);
- $flag_tva=$g_parameter->MY_TVA_USE;
- /* Add button */
- $f_add_button=new IButton('add_card');
- $f_add_button->label=_('Créer une nouvelle fiche');
- $f_add_button->tabindex=-1;
- $f_add_button->set_attribute('ipopup','ipop_newcard');
- $f_add_button->set_attribute('jrn',$this->jrn_def_id);
- $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
+ $flag_tva=$g_parameter->MY_TVA_USE;
+ /* Add button */
+ $f_add_button=new IButton('add_card');
+ $f_add_button->tabindex=-1;
+ $f_add_button->label=_('Créer une nouvelle fiche');
+ $f_add_button->set_attribute('ipopup','ipop_newcard');
+ $f_add_button->set_attribute('jrn',$p_array['p_jrn']);
+ $f_add_button->javascript="this.jrn=\$('p_jrn').value; select_card_type(this);";
- $f_add_button2=new IButton('add_card2');
- $f_add_button2->tabindex=-1;
- $f_add_button2->label=_('Créer une nouvelle fiche');
- $f_add_button2->set_attribute('ipopup','ipop_newcard');
- $f_add_button2->set_attribute('filter',$ledger->get_all_fiche_def ());
- // $f_add_button2->set_attribute('jrn',$ledger->id);
- $f_add_button2->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
- $str_add_button="";
- $str_add_button2="";
- if ($g_user->check_action(FICADD)==1)
- {
- $str_add_button=$f_add_button->input();
- $str_add_button2=$f_add_button2->input();
- }
+ $f_add_button2=new IButton('add_card2');
+ $f_add_button2->tabindex=-1;
+ $f_add_button2->label=_('Créer une nouvelle fiche');
+ $f_add_button2->set_attribute('ipopup','ipop_newcard');
+ $f_add_button2->set_attribute('filter',$ledger->get_all_fiche_def ());
+ // $f_add_button2->set_attribute('jrn',$ledger->id);
+ $f_add_button2->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
- $r="";
- $r.=dossier::hidden();
- $f_legend=_("En-tête facture fournisseur");
- $f_legend_detail=_("Détail articles acheté");
+ $str_add_button="";
+ $str_add_button2="";
+ if ($g_user->check_action(FICADD)==1)
+ {
+ $str_add_button=$f_add_button->input();
+ $str_add_button2=$f_add_button2->input();
+ }
- // Ledger (p_jrn)
- //--
- /* if we suggest the next pj, then we need a javascript */
- $add_js="";
-
- // Display the customer
- //--
- $fiche='cred';
-
- // Save old value and set a new one
- //--
- $e_client=( isset ($e_client) )?$e_client:"";
- $e_client_label=" ";//str_pad("",100,".");
+ $r='';
+ $r.=dossier::hidden();
+ $f_legend=_('En-tête facture fournisseur');
- // retrieve e_client_label
- //--
+ /* if we suggest the next pj, then we need a javascript */
- if ( strlen(trim($e_client)) != 0)
- {
- $fClient=new Fiche($ledger->db);
- $fClient->get_by_qcode($e_client);
- $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
- ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
- $fClient->strAttribut(ATTR_DEF_CP).' '.
- $fClient->strAttribut(ATTR_DEF_CITY).' ';
+ // Display the customer
+ //--
+ $fiche='deb';
+
+ // Save old value and set a new one
+ //--
+ $e_client=( isset ($p_array["e_client"]) )?$p_array["e_client"]:"";
+ $e_client_label=" ";//str_pad("",100,".");
- }
+ // retrieve e_client_label
+ //--
- $W1=new ICard();
- $W1->label=_("Fournisseur ").Icon_Action::infobulle(0) ;
- $W1->name="e_client";
- $W1->tabindex=3;
- $W1->value=$e_client;
- $W1->table=0;
- $W1->set_dblclick("fill_ipopcard(this);");
- $W1->set_attribute('ipopup','ipopcard');
-
- // name of the field to update with the name of the card
- $W1->set_attribute('label','e_client_label');
- // name of the field to update with the name of the card
- $W1->set_attribute('typecard','cred');
-
- // Add the callback function to filter the card on the jrn
- $W1->set_callback('filter_card');
- $W1->set_function('fill_data');
- $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $W1->name);
- $f_client_qcode=$W1->input();
- $client_label=new ISpan();
- $client_label->table=0;
- $f_client=$client_label->input("e_client_label",$e_client_label);
- $f_client_bt=$W1->search();
+ if ( strlen(trim($e_client)) != 0)
+ {
+ $fClient=new Fiche($ledger->db);
+ $fClient->get_by_qcode($e_client);
+ $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
+ ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
+ $fClient->strAttribut(ATTR_DEF_CP).' '.
+ $fClient->strAttribut(ATTR_DEF_CITY).' ';
- // Record the current number of article
- $min=$ledger->get_min_row();
- $p_article= ( isset ($nb_item))?$nb_item:$min;
- $max=($p_article < $min)?$min:$p_article;
+ }
- $e_comment=(isset($e_comment))?$e_comment:"";
- $Hid=new IHidden();
- $r.=$Hid->input("nb_item",$p_article);
- // For each article
- //--
- for ($i=0;$i< $max ;$i++)
- {
- // Code id, price & vat code
- //--
- $march=(isset(${"e_march$i"}))?${"e_march$i"}:"" ;
- $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
- ;
- /* use vat */
- if ( $g_parameter->MY_TVA_USE=='Y')
- {
- $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
- $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
- }
+ $W1=new ICard();
+ $W1->label="Client ".Icon_Action::infobulle(0) ;
+ $W1->name="e_client";
+ $W1->tabindex=3;
+ $W1->value=$e_client;
+ $W1->table=0;
+ $W1->set_dblclick("fill_ipopcard(this);");
+ $W1->set_attribute('ipopup','ipopcard');
+
+ // name of the field to update with the name of the card
+ $W1->set_attribute('label','e_client_label');
+ // name of the field to update with the name of the card
+ $W1->set_attribute('typecard','cred');
+
+ // Add the callback function to filter the card on the jrn
+ $W1->set_callback('filter_card');
+ $W1->set_function('fill_data');
+ $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $W1->name);
+ $f_client_qcode=$W1->input();
+ $client_label=new ISpan();
+ $client_label->table=0;
+ $f_client=$client_label->input("e_client_label",$e_client_label);
+ $f_client_bt=$W1->search();
+
+
+ // Record the current number of article
+ $min=$ledger->get_min_row();
+ $p_article= ( isset ($p_array["nb_item"]))?$p_array["nb_item"]:$min;
+ $max=($p_article < $min)?$min:$p_article;
+
+ $e_comment=(isset($p_array["e_comment"]))?$p_array["e_comment"]:"";
+ $Hid=new IHidden();
+ $r.=$Hid->input("nb_item",$p_article);
+
+ $f_legend_detail=_("Détail articles achetés");
+
+ // For each article
+ //--
+ for ($i=0;$i< $max;$i++)
+ {
+ // Code id, price & vat code
+ //--
+ $march=(isset($p_array["e_march$i"]))?$p_array["e_march$i"]:""
+ ;
+ $march_price=(isset($p_array["e_march".$i."_price"]))?$p_array["e_march".$i."_price"]:""
+ ;
+ if ( $flag_tva=='Y')
+ {
+ $march_tva_id=(isset($p_array["e_march$i"."_tva_id"]))?$p_array["e_march$i"."_tva_id"]:"";
+ $march_tva_amount=(isset($p_array["e_march$i"."_tva_amount"]))?$p_array["e_march$i"."_tva_amount"]:"";
+ }
+ $march_label=(isset($p_array["e_march".$i."_label"]))?$p_array["e_march".$i."_label"]:"";
+
+ // retrieve the tva label and name
+ //--
+ if ( strlen(trim($march))!=0 && strlen(trim($march_label))==0)
+ {
+ $fMarch=new Fiche($ledger->db);
+ $fMarch->get_by_qcode($march);
+ $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
+ if ( $flag_tva=='Y')
+ {
+ if ( ! (isset($p_array["e_march$i"."_tva_id"])))
+ $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
+ }
+ }
+ // Show input
+ //--
+ $W1=new ICard();
+ $W1->label="";
+ $W1->name="e_march".$i;
+ $W1->value=$march;
+ $W1->table=1;
+ $W1->set_attribute('typecard','deb');
+ $W1->set_dblclick("fill_ipopcard(this);");
+ $W1->set_attribute('ipopup','ipopcard');
+
+ // name of the field to update with the name of the card
+ $W1->set_attribute('label','e_march'.$i.'_label');
+ // name of the field with the price
+ $W1->set_attribute('price','e_march'.$i.'_price');
+ // name of the field with the TVA_ID
+ $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
+ // Add the callback function to filter the card on the jrn
+ $W1->set_callback('filter_card');
+ $W1->set_function('fill_data');
+ $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+ $W1->name);
+
+ $W1->readonly=false;
+
+ $array[$i]['quick_code']=$W1->input();
+ $array[$i]['bt']=$W1->search();
+ // For computing we need some hidden field for holding the value
+ $array[$i]['hidden']='';
+ if ( $flag_tva=='Y') $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
+
+ $htva=new INum('htva_march'.$i);
+ $htva->readOnly=1;
+ $htva->value=0;
+ $array[$i]['htva']=$htva->input();
+
+ if ( $g_parameter->MY_TVA_USE=='Y')
+ $tvac=new INum('tvac_march'.$i);
+ else
+ $tvac=new IHidden('tvac_march'.$i);
+
+ $tvac->readOnly=1;
+ $tvac->value=0;
+ $array[$i]['tvac']=$tvac->input();
+
+ if ( $g_parameter->MY_UPDLAB == 'Y')
+ {
+ $Span=new IText("e_march".$i."_label");
+
+ $Span->css_size="100%";
+ } else
+ {
+ $Span=new ISpan("e_march".$i."_label");
+ }
+ $Span->value=$march_label;
+ $Span->setReadOnly(false);
+ // card's name, price
+ //--
+ $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
+ // price
+ $Price=new INum();
+ $Price->setReadOnly(false);
+ $Price->prec=4;
+ $Price->size=9;
+ $Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
+ $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
+ $array[$i]['tva']='';
+ $array[$i]['amount_tva']='';
+ // if tva is not needed then no tva field
+ if ( $flag_tva == 'Y' )
+ {
+ // vat label
+ //--
+ $Tva=new ITva_Popup($ledger->db);
+ $Tva->in_table=true;
+ $Tva->set_attribute('compute',$i);
+
+ $Tva->js='onblur="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
+ $Tva->value=$march_tva_id;
+ $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
+ // vat amount
+ //--
+ $wTva_amount=new INum();
+ $wTva_amount->readOnly=false;
+ $wTva_amount->size=6;
+ $wTva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
+ $array[$i]['amount_tva']=$wTva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
+ }
+ // quantity
+ //--
+ $quant=(isset($p_array["e_quant$i"]))?$p_array["e_quant$i"]:"1"
+ ;
+ $Quantity=new INum();
+ $Quantity->setReadOnly(false);
+ $Quantity->size=8;
+ $Quantity->javascript="onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
+ $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
+
+ }// foreach article
+ $f_type=_('Client');
+
+
+ ob_start();
+ require_once NOALYSS_TEMPLATE.'/predf_ledger_detail.php';
+ $r.=ob_get_contents();
+ ob_end_clean();
- $march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
- // retrieve the tva label and name
- //--
- if ( strlen(trim($march))!=0 && strlen(trim($march_label))==0 )
- {
- $fMarch=new Fiche($ledger->db);
- $fMarch->get_by_qcode($march);
- $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
- /* vat use */
- if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
- $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
- }
- // Show input
- //--
- $W1=new ICard();
- $W1->label="";
- $W1->name="e_march".$i;
- $W1->value=$march;
- $W1->table=1;
- $W1->set_dblclick("fill_ipopcard(this);");
- $W1->set_attribute('ipopup','ipopcard');
+ // Set correctly the REQUEST param for jrn_type
+ $r.=HtmlInput::hidden('jrn_type','ACH');
+ $r.= Html_Input_Noalyss::ledger_add_item("O");
- $W1->set_attribute('typecard','deb');
-
- // name of the field to update with the name of the card
- $W1->set_attribute('label','e_march'.$i.'_label');
- // name of the field with the price
- $W1->set_attribute('purchase','e_march'.$i.'_price'); /* autocomplete */
- $W1->set_attribute('price','e_march'.$i.'_price'); /* via search */
-
- // name of the field with the TVA_ID
- $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
- // Add the callback function to filter the card on the jrn
- $W1->set_callback('filter_card');
- $W1->set_function('fill_data');
- $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
- $W1->name);
- $W1->readonly=false;
- $array[$i]['quick_code']=$W1->input();
- $array[$i]['bt']=$W1->search();
-
- $array[$i]['hidden']='';
- // For computing we need some hidden field for holding the value
- if ( $g_parameter->MY_TVA_USE=='Y')
- {
- $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
- }
-
- if ( $g_parameter->MY_TVA_USE=='Y')
- $tvac=new INum('tvac_march'.$i);
- else
- $tvac=new IHidden('tvac_march'.$i);
-
- $tvac->readOnly=1;
- $tvac->value=0;
- $array[$i]['tvac']=$tvac->input();
-
- $htva=new INum('htva_march'.$i);
- $htva->readOnly=1;
-
- $htva->value=0;
- $array[$i]['htva']=$htva->input();
-
- if ( $g_parameter->MY_UPDLAB == 'Y')
- {
- $Span=new IText("e_march".$i."_label");
- $Span->css_size="100%";
- } else
- {
- $Span=new ISpan("e_march".$i."_label");
- }
- $Span->value=$march_label;
- $Span->setReadOnly(false);
- // card's name, price
- //--
- $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
- // price
- $Price=new INum();
- $Price->prec=4;
- $Price->setReadOnly(false);
- $Price->size=9;
- $Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
- $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
- if ( $g_parameter->MY_TVA_USE=='Y')
- {
-
- // vat label
- //--
- $Tva=new ITva_Popup($ledger->db);
- $Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
- $Tva->in_table=true;
- $Tva->set_attribute('compute',$i);
- $Tva->value=$march_tva_id;
- $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
-
- // Tva_amount
-
- // price
- $Tva_amount=new INum();
- $Tva_amount->setReadOnly(false);
- $Tva_amount->size=9;
- $Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
- $array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
- }
- // quantity
- //--
- $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
- ;
- $Quantity=new INum();
- $Quantity->setReadOnly(false);
- $Quantity->size=9;
- $Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
- $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
-
- }
- $f_type=_('Fournisseur');
-
- ob_start();
- require_once NOALYSS_TEMPLATE.'/predf_ledger_detail.php';
- $r.=ob_get_contents();
- ob_end_clean();
-
- // Set correctly the REQUEST param for jrn_type
- $r.= HtmlInput::hidden('jrn_type','ACH');
- $r.= Html_Input_Noalyss::ledger_add_item("O");
+ return $r;
return $r;
}
diff --git a/include/class/pre_op_advanced.class.php b/include/class/pre_op_advanced.class.php
index 3d78bc9e7..8c08e7094 100644
--- a/include/class/pre_op_advanced.class.php
+++ b/include/class/pre_op_advanced.class.php
@@ -29,18 +29,16 @@ require_once NOALYSS_INCLUDE.'/class/pre_operation.class.php';
*/
class Pre_Op_Advanced extends Pre_operation_detail
{
- var $op;
function __construct($cn)
{
parent::__construct($cn);
- $this->operation->od_direct='t';
}
function get_post()
{
- parent::get_post();
- $http=new HttpInput();
+ $http = new \HttpInput();
+ $nb = $http->post("nb_item", "number");
- for ($i=0;$i<$this->operation->nb_item;$i++)
+ for ($i=0;$i<$nb;$i++)
{
$poste=$http->post("poste".$i,"string", null);
$qcode=$http->post("qc_".$i,"string", null);
@@ -54,10 +52,14 @@ class Pre_Op_Advanced extends Pre_operation_detail
}
if ( $qcode != null && trim ($qcode) != "") {
- $this->{'isqc'.$i}=(trim($_POST['qc_'.$i]) != "")?'t':'f';
+ $this->{'isqc'.$i}=(trim($http->post('qc_'.$i)) != "")?'t':'f';
$this->{'poste'.$i}=trim ($qcode);
- }
- $this->{"amount".$i}=$_POST['amount'.$i];
+ }
+ $http->set_empty(0);
+ $this->{"amount".$i}=$http->post('amount'.$i);
+ $http->set_empty("");
+ $this->{"ld".$i}=$http->post("ld".$i);
+
$this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
}
@@ -66,60 +68,53 @@ class Pre_Op_Advanced extends Pre_operation_detail
* \brief save the detail and op in the database
*
*/
- function save()
+ function save($p_od_id,$p_nb_item)
{
try
{
- if ($this->operation->save() == false )
- return;
- $this->db->start();
// save the selling
- for ($i=0;$i<$this->operation->nb_item;$i++)
+ for ($i=0;$i<$p_nb_item;$i++)
{
if ( ! isset ($this->{"poste".$i}))
continue;
$sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
- 'opd_debit,od_id,opd_qc)'.
- ' values '.
- "('%s',%.2f,'%s',%d,'%s')",
- $this->{"poste".$i},
- $this->{"amount".$i},
- $this->{"ck".$i},
- $this->operation->od_id,
- $this->{'isqc'.$i}
+ 'opd_debit,od_id,opd_qc,opd_comment)'.
+ ' values($1,$2,$3,$4,$5,$6) '
);
- $this->db->exec_sql($sql);
+ $this->db->exec_sql($sql,[$this->{"poste".$i},
+ $this->{"amount".$i},
+ $this->{"ck".$i},
+ $p_od_id,
+ $this->{'isqc'.$i},
+ $this->{"ld".$i}]);
}
- $this->db->commit();
-
+
}
catch (Exception $e)
{
- record_log($e);
- echo ($e->getMessage());
- $this->db->rollback();
+ record_log($e->getMessage().$e->getTraceAsString());
+ throw $e;
}
}
/*!\brief compute an array accordingly with the FormVenView function
*/
- function compute_array()
+ function compute_array($p_od_id)
{
$count=0;
- $a_op=$this->operation->load();
- $array=$this->operation->compute_array($a_op);
- $array['desc']=$array['e_comm'];
- $p_array=$this->load();
+ $array=array();
+ $p_array=$this->load($p_od_id);
if (empty($p_array)) return array();
foreach ($p_array as $row)
{
$tmp_array=array("qc_".$count=>'',
"poste".$count=>'',
"amount".$count=>$row['opd_amount'],
- 'ck'.$count=>$row['opd_debit']
+ 'ck'.$count=>$row['opd_debit'],
+ "ld".$count=>$row['opd_comment']
);
if ( $row['opd_qc'] == 't' )
@@ -141,28 +136,22 @@ class Pre_Op_Advanced extends Pre_operation_detail
/*!\brief load the data from the database and return an array
* \return an array
*/
- function load()
+ function load($p_od_id)
{
- $sql="select opd_id,opd_poste,opd_amount,opd_debit,".
- " opd_qc from op_predef_detail where od_id=".$this->operation->od_id.
+ $sql="select opd_id,opd_poste,opd_amount,opd_debit,opd_comment,".
+ " opd_qc from op_predef_detail where od_id=$1 ".
" order by opd_id";
- $res=$this->db->exec_sql($sql);
+ $res=$this->db->exec_sql($sql,[$p_od_id]);
$array=Database::fetch_all($res);
return $array;
}
- function set_od_id($p_id)
- {
- $this->operation->od_id=$p_id;
- }
- function display($p_array)
+ function display($p_array)
{
global $g_parameter, $g_user;
require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
- $legder=new Acc_Ledger($this->db,$this->jrn_def_id);
+ $legder=new Acc_Ledger($this->db,$p_array['p_jrn']);
$legder->nb=$legder->get_min_row();
- if ($p_array != null)
- extract($p_array, EXTR_SKIP);
$add_js = "";
$ret = "";
@@ -177,10 +166,10 @@ class Pre_Op_Advanced extends Pre_operation_detail
$f_add_button->input();
}
- $nb_row = (isset($nb_item) ) ? $nb_item : $legder->nb;
+ $nb_row = (isset($p_array['nb_item']) ) ? $p_array['nb_item' ]: $legder->nb;
$ret.=HtmlInput::hidden('nb_item', $nb_row);
- $ret.=HtmlInput::hidden('p_jrn', $this->jrn_def_id);
+ $ret.=HtmlInput::hidden('p_jrn', $p_array['p_jrn']);
$ret.=dossier::hidden();
$ret.=dossier::hidden();
@@ -220,7 +209,7 @@ class Pre_Op_Advanced extends Pre_operation_detail
$quick_code->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
$quick_code->jrn = $legder->id;
- $quick_code->value = (isset(${'qc_' . $i})) ? ${'qc_' . $i} : "";
+ $quick_code->value = (isset($p_array['qc_' . $i])) ? $p_array['qc_' . $i]: "";
$label = '';
if ($quick_code->value != '')
@@ -240,7 +229,7 @@ class Pre_Op_Advanced extends Pre_operation_detail
$poste->set_attribute('account', 'poste' . $i);
$poste->set_attribute('dossier', Dossier::id());
- $poste->value = (isset(${'poste' . $i})) ? ${"poste" . $i} : ''
+ $poste->value = (isset($p_array['poste' . $i])) ?$p_array['poste' . $i]: ''
;
$poste->dbl_click_history();
@@ -256,20 +245,20 @@ class Pre_Op_Advanced extends Pre_operation_detail
$line_desc = new IText();
$line_desc->name = 'ld' . $i;
$line_desc->size = 30;
- $line_desc->value = (isset(${"ld" . $i})) ? ${"ld" . $i} :
+ $line_desc->value = (isset($p_array["ld" . $i])) ? $p_array["ld" . $i] :
$label;
// Amount
$amount = new INum();
$amount->size = 10;
$amount->name = 'amount' . $i;
- $amount->value = (isset(${'amount' . $i})) ? ${"amount" . $i} : ''
+ $amount->value = (isset($p_array['amount' . $i])) ?$p_array['amount' . $i] : ''
;
$amount->javascript = ' onChange="format_number(this);checkTotalDirect()"';
// D/C
$deb = new ICheckBox();
$deb->name = 'ck' . $i;
- $deb->selected = (isset(${'ck' . $i})) ? true : false;
+ $deb->selected = (isset($p_array['ck' . $i])) ? true : false;
$deb->javascript = ' onChange="checkTotalDirect()"';
$ret.='
';
diff --git a/include/class/pre_op_ods.class.php b/include/class/pre_op_ods.class.php
index 1130e6208..9b1d8696f 100644
--- a/include/class/pre_op_ods.class.php
+++ b/include/class/pre_op_ods.class.php
@@ -30,22 +30,23 @@ require_once NOALYSS_INCLUDE.'/class/pre_operation.class.php';
class Pre_op_ods extends Pre_operation_detail
{
var $op;
- function __construct($cn,$p_id=0)
+ function __construct($cn)
{
- parent::__construct($cn,$p_id);
- $this->operation->od_direct='f';
+ parent::__construct($cn);
}
+ /***
+ * @brief retrieve data from $_POST
+ */
function get_post()
{
- parent::get_post();
- $this->operation->od_direct='f';
- for ($i=0;$i<$this->operation->nb_item;$i++)
+ $http=new \HttpInput();
+ $nb=$http->post("nb_item","number");
+ for ($i=0;$i< $nb ;$i++)
{
-
- $this->{"e_account".$i}=$_POST['e_account'.$i];
- $this->{"e_account".$i."_amount"}=$_POST['e_account'.$i."_amount"];
- $this->{"e_account".$i."_type"}=$_POST['e_account'.$i."_type"];
+ $this->{"e_account".$i}=$http->post("e_account'.$i");
+ $this->{"e_account".$i."_amount"}=$http->post("e_account".$i."_amount","number",0);
+ $this->{"e_account".$i."_type"}=$http->post('e_account'.$i."_type");
}
}
@@ -53,45 +54,38 @@ class Pre_op_ods extends Pre_operation_detail
* \brief save the detail and op in the database
*
*/
- function save()
+ function save($p_od_id,$p_nbitem)
{
try
{
- $this->db->start();
- if ($this->operation->save() == false )
- return;
-
// save the selling
- for ($i=0;$i<$this->operation->nb_item;$i++)
+ for ($i=0;$i< $p_nbitem ;$i++)
{
- $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
+ $sql='insert into op_predef_detail (opd_poste,opd_amount,'.
'opd_debit,od_id)'.
- ' values '.
- "('%s',%.2f,'%s',%d)",
- $this->{"e_account".$i},
- $this->{"e_account".$i."_amount"},
- ($this->{"e_account".$i."_type"}=='d')?'t':'f',
- $this->operation->od_id
- );
- $this->db->exec_sql($sql);
+ ' values ($1,$2,$3,$4)';
+
+ $this->db->exec_sql($sql,array($this->{"e_account".$i},
+ $this->{"e_account".$i."_amount"},
+ ($this->{"e_account".$i."_type"}=='d')?'t':'f',
+ $p_od_id)
+ );
}
}
catch (Exception $e)
{
- record_log($e);
+ record_log($e);
echo ($e->getMessage());
- $this->db->rollback();
+ throw $e;
}
}
/*!\brief compute an array accordingly with the FormVenView function
*/
- function compute_array()
+ function compute_array($p_od_id)
{
$count=0;
- $a_op=$this->operation->load();
- $array=$this->operation->compute_array($a_op);
- $p_array=$this->load();
+ $p_array=$this->load($p_od_id);
foreach ($p_array as $row)
{
$c=($row['opd_debit']=='t')?'d':'c';
@@ -107,17 +101,13 @@ class Pre_op_ods extends Pre_operation_detail
/*!\brief load the data from the database and return an array
* \return an array
*/
- function load()
+ function load($p_od_id)
{
$sql="select opd_id,opd_poste,opd_amount,opd_debit".
- " from op_predef_detail where od_id=".$this->operation->od_id.
+ " from op_predef_detail where od_id= $1 ".
" order by opd_debit, opd_id,opd_amount";
- $res=$this->db->exec_sql($sql);
+ $res=$this->db->exec_sql($sql,array($p_od_id));
$array=Database::fetch_all($res);
return $array;
}
- function set_od_id($p_id)
- {
- $this->operation->od_id=$p_id;
- }
}
diff --git a/include/class/pre_op_ven.class.php b/include/class/pre_op_ven.class.php
index 3d97c0687..fbb0cbc97 100644
--- a/include/class/pre_op_ven.class.php
+++ b/include/class/pre_op_ven.class.php
@@ -29,53 +29,49 @@ require_once NOALYSS_INCLUDE.'/class/pre_operation.class.php';
*/
class Pre_op_ven extends Pre_operation_detail
{
- var $op;
//< Pre_operation
- function __construct($cn,$p_id=0)
+ function __construct($cn)
{
- parent::__construct($cn,$p_id);
- $this->operation->od_direct='f'; //< Pre_operation
+ parent::__construct($cn);
}
function get_post()
{
- parent::get_post();
- $this->operation->od_direct='f';
- $this->e_client=$_POST['e_client'];
- for ($i=0;$i<$this->operation->nb_item;$i++)
+ $http=new \HttpInput();
+ $nb=$http->post("nb_item","number");
+ $this->e_client=$http->post("e_client");
+ for ($i=0;$i< $nb;$i++)
{
$march="e_march".$i;
- $this->$march=$_POST['e_march'.$i];
- $this->{"e_march".$i."_price"}=$_POST['e_march'.$i."_price"];
- $this->{"e_march".$i."_tva_id"}=(isset($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
- $this->{"e_march".$i."_tva_amount"}=(isset($_POST['e_march'.$i."_tva_amount"]))?$_POST['e_march'.$i."_tva_amount"]:0;
- $this->{"e_march".$i."_tva_id"}=(isset($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
- $this->{"e_march".$i."_label"}=(isset($_POST['e_march'.$i."_label"]))?$_POST['e_march'.$i."_label"]:null;
- $this->{"e_quant".$i}=$_POST['e_quant'.$i];
+ $http->set_empty("");
+ $this->$march=$http->post('e_march'.$i);
+ $this->{"e_march".$i."_tva_id"}=$http->post('e_march'.$i."_tva_id","string",0);
+ $this->{"e_march".$i."_tva_id"}=$http->post('e_march'.$i."_tva_id","string","0");
+ $this->{"e_march".$i."_label"}=$http->post('e_march'.$i."_label","string","");
+ $http->set_empty(0);
+ $this->{"e_march".$i."_price"}=$http->post('e_march'.$i."_price","number");
+ $this->{"e_march".$i."_tva_amount"}=$http->post('e_march'.$i."_tva_amount","number","0");
+ $this->{"e_quant".$i}=$http->post('e_quant'.$i,"number");
}
}
/*!
* \brief save the detail and op in the database
*
*/
- function save()
+ function save($p_od_id,$p_nb_item)
{
try
{
- $this->db->start();
- if ($this->operation->save() == false )
- return;
// save the client
$sql=sprintf('insert into op_predef_detail (od_id,opd_poste,opd_debit)'.
- ' values '.
- "(%d,'%s','%s')",
- $this->operation->od_id,
- $this->e_client,
- "t");
+ ' values '.
+ "(%d,'%s','%s')",
+ $p_od_id,
+ $this->e_client,
+ "t");
$this->db->exec_sql($sql);
- // save the selling
- for ($i=0;$i<$this->operation->nb_item;$i++)
+ for ($i=0;$i<$p_nb_item;$i++)
{
if ( strlen(trim($this->{"e_march".$i}))=="") continue;
$sql= 'insert into op_predef_detail (opd_poste,'
@@ -94,7 +90,7 @@ class Pre_op_ven extends Pre_operation_detail
$this->{"e_march".$i."_tva_id"},
$this->{"e_quant".$i},
'f',
- $this->operation->od_id,
+ $p_od_id,
$this->{"e_march".$i."_tva_amount"},
$this->{"e_march".$i."_label"},
));
@@ -102,21 +98,17 @@ class Pre_op_ven extends Pre_operation_detail
}
catch (Exception $e)
{
- record_log($e);
- echo ($e->getMessage());
- $this->db->rollback();
+ record_log("PREOPVEN01".$e->getMessage().$e->getTraceAsString());
+ throw $e;
}
- $this->db->commit();
-
}
/*!\brief compute an array accordingly with the FormVenView function
*/
- function compute_array()
+ function compute_array($p_od_id)
{
$count=0;
- $a_op=$this->operation->load();
- $array=$this->operation->compute_array($a_op);
- $p_array=$this->load();
+ $array=array();
+ $p_array=$this->load($p_od_id);
if (empty($p_array)) return array();
foreach ($p_array as $row)
{
@@ -139,37 +131,33 @@ class Pre_op_ven extends Pre_operation_detail
}
}
}
- // Find the ledger
- $ledger=new Acc_Ledger($this->db,$this->operation->jrn_def_id);
- // Find the max line of the ledger
- $max_row=$ledger->get_min_row();
-
- // compute nb_item
- $array['nb_item']=($max_row > $count)?$max_row:$count;
+
return $array;
}
/*!\brief load the data from the database and return an array
* \return an array
*/
- function load()
+ function load($p_od_id)
{
$sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,".
- " opd_quantity , opd_comment,opd_tva_amount from op_predef_detail where od_id=".$this->operation->od_id.
+ " opd_quantity , opd_comment,opd_tva_amount from op_predef_detail where od_id= $1 ".
" order by opd_id";
- $res=$this->db->exec_sql($sql);
+ $res=$this->db->exec_sql($sql,[$p_od_id]);
$array=Database::fetch_all($res);
return $array;
}
- function set_od_id($p_id)
- {
- $this->operation->od_id=$p_id;
- }
+
+ /**
+ * @param array $p_array
+ * @return string
+ * @throws Exception
+ */
function display($p_array)
{
global $g_parameter,$g_user;
- if ( $p_array != null ) extract($p_array, EXTR_SKIP);
+
require_once NOALYSS_INCLUDE.'/class/acc_ledger_sold.class.php';
- $ledger=new Acc_Ledger_Sold($this->db,$this->jrn_def_id);
+ $ledger=new Acc_Ledger_Sold($this->db,$p_array['p_jrn']);
$flag_tva=$g_parameter->MY_TVA_USE;
/* Add button */
@@ -177,7 +165,7 @@ class Pre_op_ven extends Pre_operation_detail
$f_add_button->tabindex=-1;
$f_add_button->label=_('Créer une nouvelle fiche');
$f_add_button->set_attribute('ipopup','ipop_newcard');
- $f_add_button->set_attribute('jrn',$ledger->id);
+ $f_add_button->set_attribute('jrn',$p_array['p_jrn']);
$f_add_button->javascript="this.jrn=\$('p_jrn').value; select_card_type(this);";
$f_add_button2=new IButton('add_card2');
@@ -209,7 +197,7 @@ class Pre_op_ven extends Pre_operation_detail
// Save old value and set a new one
//--
- $e_client=( isset ($e_client) )?$e_client:"";
+ $e_client=( isset ($p_array["e_client"]) )?$p_array["e_client"]:"";
$e_client_label=" ";//str_pad("",100,".");
@@ -256,10 +244,10 @@ class Pre_op_ven extends Pre_operation_detail
// Record the current number of article
$min=$ledger->get_min_row();
- $p_article= ( isset ($nb_item))?$nb_item:$min;
+ $p_article= ( isset ($p_array["nb_item"]))?$p_array["nb_item"]:$min;
$max=($p_article < $min)?$min:$p_article;
- $e_comment=(isset($e_comment))?$e_comment:"";
+ $e_comment=(isset($p_array["e_comment"]))?$p_array["e_comment"]:"";
$Hid=new IHidden();
$r.=$Hid->input("nb_item",$p_article);
@@ -271,16 +259,16 @@ class Pre_op_ven extends Pre_operation_detail
{
// Code id, price & vat code
//--
- $march=(isset(${"e_march$i"}))?${"e_march$i"}:""
+ $march=(isset($p_array["e_march$i"]))?$p_array["e_march$i"]:""
;
- $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
+ $march_price=(isset($p_array["e_march".$i."_price"]))?$p_array["e_march".$i."_price"]:""
;
if ( $flag_tva=='Y')
{
- $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
- $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
+ $march_tva_id=(isset($p_array["e_march$i"."_tva_id"]))?$p_array["e_march$i"."_tva_id"]:"";
+ $march_tva_amount=(isset($p_array["e_march$i"."_tva_amount"]))?$p_array["e_march$i"."_tva_amount"]:"";
}
- $march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
+ $march_label=(isset($p_array["e_march".$i."_label"]))?$p_array["e_march".$i."_label"]:"";
// retrieve the tva label and name
//--
@@ -291,7 +279,7 @@ class Pre_op_ven extends Pre_operation_detail
$march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
if ( $flag_tva=='Y')
{
- if ( ! (isset(${"e_march$i"."_tva_id"})))
+ if ( ! (isset($p_array["e_march$i"."_tva_id"])))
$march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
}
}
@@ -385,7 +373,7 @@ class Pre_op_ven extends Pre_operation_detail
}
// quantity
//--
- $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
+ $quant=(isset($p_array["e_quant$i"]))?$p_array["e_quant$i"]:"1"
;
$Quantity=new INum();
$Quantity->setReadOnly(false);
diff --git a/include/class/pre_operation.class.php b/include/class/pre_operation.class.php
index 8243b58bb..28a35f40e 100644
--- a/include/class/pre_operation.class.php
+++ b/include/class/pre_operation.class.php
@@ -34,19 +34,29 @@ require_once NOALYSS_INCLUDE.'/class/pre_op_ven.class.php';
require_once NOALYSS_INCLUDE.'/class/pre_op_advanced.class.php';
class Pre_operation
{
- var $db; /*!< $db database connection */
- var $nb_item; /*!< $nb_item nb of item */
- var $p_jrn; /*!< $p_jrn jrn_def_id */
- var $jrn_type; /*!< $jrn_type */
- var $name; /*!< $name name of the predef. operation */
- var $detail; /*!< Pre_operation_detail */
-
+ private $db; /*!< $db database connection */
+ private $nb_item; /*!< $nb_item nb of item */
+ private $p_jrn; /*!< $p_jrn jrn_def_id */
+ private $jrn_type; /*!< $jrn_type */
+ private $name; /*!< $name name of the predef. operation */
+ private $detail; /*!< Pre_operation_detail object */
+ private $od_direct ; /*!< Compatibility for ACH in direct mode, only for ODS */
+ private $od_id; /*!< id of the Predefined Operation */
+ private $isloaded;
+ private $description; /*!< description of the predefined operation */
function __construct($cn,$p_id=0)
{
$this->db=$cn;
- $this->od_direct='false';
+ $this->od_direct='f';
$this->od_id=$p_id;
+ $this->p_jrn=0;
+ $this->jrn_type='x';
+ $this->name='';
+ $this->isloaded=false;
+ $this->description="";
+
}
+
/**
* @brief Propose to save the operation into a predefined operation
* @return HTML string
@@ -56,7 +66,7 @@ class Pre_operation
$r.= '
';
$r.= _("Donnez un nom pour sauver cette opération comme modèle")." ";
$opd_name = new IText('opd_name');
- $r.= "Nom du modèle " . $opd_name->input();
+ $r.=_( "Nom du modèle " ) . $opd_name->input();
$opd_description=new ITextarea('od_description');
$opd_description->style=' class="itextarea" style="width:30em;height:4em;vertical-align:top"';
$r.='
';
@@ -67,6 +77,21 @@ class Pre_operation
$r.='';
return $r;
}
+ /**
+ * @return string
+ */
+ public function get_description()
+ {
+ return $this->description;
+ }/**
+ * @param string $description
+ */
+ public function set_description($description)
+ {
+ $this->description = $description;
+ return $this;
+ }
+
/*!\brief fill the object with the $_POST variable */
function get_post()
@@ -77,29 +102,55 @@ class Pre_operation
$this->jrn_type=$http->post('jrn_type');
$this->name=$http->post('opd_name');
- $this->name=(trim($this->name)=='')?$http->post('e_comm'):$this->name;
$this->description= $http->post('od_description');
if ( $this->name=="")
{
$n=$this->db->get_next_seq('op_def_op_seq');
$this->name=$this->jrn_type.$n;
- // common value
+
}
+
+ // get also info for the details
+ // common value
+ $this->detail=Pre_operation_detail::build_detail($this->jrn_type,$this->db);
+ $this->detail->get_post();
}
+
+ /**
+ * delete a template operation and children
+ */
function delete ()
{
$sql="delete from op_predef where od_id=$1";
$this->db->exec_sql($sql,array($this->od_id));
}
+ function save()
+ {
+ if ($this->od_id < 1) {
+ $this->save_insert();
+ } else {
+ $this->save_update();
+ }
+
+ }
+ function save_update()
+ {
+ $sql = "update op_predef set jrn_def_id = $1 , od_name = $2 ,
+ od_item =$3, od_description = $4 where od_id=$5";
+ $this->db->exec_sql($sql,array($this->p_jrn,$this->name,$this->nb_item,$this->description,$this->od_id));
+ // delete detail&
+ $this->db->exec_sql("delete from op_predef_detail where od_id = $1",array($this->od_id));
+ $this->detail->save($this->od_id,$this->nb_item);
+ }
/*!\brief save the predef check first is the name is unique
* \return true op.success otherwise false
*/
- function save()
+ function save_insert()
{
if ( $this->db->count_sql("select * from op_predef ".
"where upper(od_name)=upper('".Database::escape_string($this->name)."')".
- "and jrn_def_id=".$this->p_jrn)
+ "and jrn_def_id=".$this->p_jrn." and od_id <> ".$this->od_id)
!= 0 )
{
$this->name="copy_".$this->name."_".microtime(true);
@@ -109,24 +160,44 @@ class Pre_operation
echo ''.("Vous avez atteint le max. d'opération prédéfinie, désolé").'';
return false;
}
- $sql='insert into op_predef (jrn_def_id,od_name,od_item,od_jrn_type,od_direct,od_description)'.
- 'values'.
- "($1,$2,$3,$4,$5 ,$6 )";
- $this->db->exec_sql($sql,array($this->p_jrn,
- $this->name,
- $this->nb_item,
- $this->jrn_type,
- $this->od_direct,
- $this->description,
+ try {
+ $this->db->start();
+ $sql='insert into op_predef (jrn_def_id,od_name,od_item,od_jrn_type,od_direct,od_description)'.
+ 'values'.
+ "($1,$2,$3,$4,$5 ,$6 )";
+ $this->db->exec_sql($sql,array($this->p_jrn,
+ $this->name,
+ $this->nb_item,
+ $this->jrn_type,
+ $this->od_direct,
+ $this->description,
));
- $this->od_id=$this->db->get_current_seq('op_def_op_seq');
+ $this->od_id=$this->db->get_current_seq('op_def_op_seq');
+
+
+ // $this->detail=Pre_operation_detail::build_detail($this->jrn_type,$this->db);
+ $this->detail->save($this->od_id,$this->nb_item);
+ $this->db->commit();
+ } catch (Exception $e) {
+ record_log("PROP139.Failed save predefined operation ");
+ $this->db->rollback();
+ }
+
return true;
}
/*!\brief load the data from the database and return an array
- * \return an array
+ * \return an double array containing all the data from database
*/
function load()
{
+ $this->isloaded=true;
+ //------------------------------------------
+ // if new , then od_id == 0 and we need to use blank()
+ //------------------------------------------
+ if ($this->od_id == -1 ) {
+ $array=$this->blank($this->p_jrn);
+ return $array;
+ }
$sql="select od_id,jrn_def_id,od_name,od_item,od_jrn_type,od_description".
" from op_predef where od_id=$1 ".
" order by od_name";
@@ -135,27 +206,41 @@ class Pre_operation
foreach (array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as $field) {
$this->$field=$array[0][$field];
}
- switch ($this->od_jrn_type) {
- case 'ACH':
- $this->detail=new Pre_op_ach($this->db);
- break;
- case 'VEN':
- $this->detail=new Pre_Op_ven($this->db);
- break;
- case 'ODS':
- $this->detail=new Pre_op_advanced($this->db);
- break;
- default:
- throw new Exception(sprintf(_('Echec PreOperatoin chargement %s'),$this->od_jrn_type));
- }
- $this->detail->set_od_id($this->od_id);
- $this->detail->jrn_def_id=$this->jrn_def_id;
-
+ $this->detail = Pre_operation_detail::build_detail($this->od_jrn_type, $this->db);
+ $array+=$this->detail->load($this->od_id);
return $array;
}
+ /**
+ * create a blank object to insert it later
+ * @param $p_ledger_id
+ * @throws Exception
+ */
+ function blank($p_ledger_id) {
+ $array["od_id"]=-1;
+ $array['jrn_def_id']=$p_ledger_id;
+ $array['od_name']="";
+ $array['od_item']=2;
+ $array['od_jrn_type']=$this->db->get_value("select jrn_def_type from jrn_def where jrn_def_id=$1",[$p_ledger_id]);
+ $array['od_description']="";
+ foreach (array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as $field) {
+ $this->$field=$array[$field];
+ }
+ $this->od_jrn_type=$array['od_jrn_type'];
+
+ $this->detail = Pre_operation_detail::build_detail($this->od_jrn_type, $this->db);
+ $this->detail->set_od_id(0);
+ $this->detail->set_jrn($p_ledger_id);
+
+ return $array;
+ }
+
function compute_array()
{
- $p_array=$this->load();
+ if ($this->od_id > 0) {
+ $p_array = $this->load();
+ } else {
+ $p_array=$this->blank($this->p_jrn);
+ }
$array=array(
"e_comm"=>$p_array[0]["od_name"],
"nb_item"=>(($p_array[0]["od_item"]<10)?10:$p_array[0]["od_item"]) ,
@@ -163,6 +248,8 @@ class Pre_operation
"jrn_type"=>$p_array[0]["od_jrn_type"],
"od_description"=>$p_array['0']['od_description']
);
+ $this->detail = Pre_operation_detail::build_detail($this->od_jrn_type, $this->db);
+ $array += $this->detail->compute_array($this->od_id);
return $array;
}
@@ -187,9 +274,9 @@ class Pre_operation
function count()
{
$a=$this->db->count_sql("select od_id,od_name from op_predef ".
- " where jrn_def_id=".$this->p_jrn.
- " and od_direct ='".$this->od_direct."'".
- " order by od_name");
+ " where jrn_def_id= $1 ".
+ " and od_direct = $2 ".
+ " order by od_name",array($this->p_jrn,$this->od_direct));
return $a;
}
/*!\brief get the list of the predef. operation of a ledger
@@ -198,21 +285,14 @@ class Pre_operation
function get_list_ledger()
{
$sql="select od_id,od_name,od_description from op_predef ".
- " where jrn_def_id=".$this->p_jrn.
- " and od_direct ='".$this->od_direct."'".
+ " where jrn_def_id= $1 ".
+ " and od_direct = $2 ".
" order by od_name";
- $res=$this->db->exec_sql($sql);
+ $res=$this->db->exec_sql($sql,array($this->p_jrn,$this->od_direct));
$all=Database::fetch_all($res);
return $all;
}
- /*!\brief set the ledger
- * \param $p_jrn is the ledger (jrn_id)
- */
- function set_jrn($p_jrn)
- {
- $this->p_jrn=$p_jrn;
- }
-
+
/**
*
* @brief display the detail of predefined operation, normally everything
@@ -220,67 +300,43 @@ class Pre_operation
*/
function display()
{
- $array=$this->detail->compute_array();
+ $array=$this->compute_array();
+ require NOALYSS_TEMPLATE."/pre_operation_display.php";
echo $this->detail->display($array);
}
-}
-
-/*!\brief mother of the pre_op_XXX, it contains only one data : an
- * object Pre_Operation. The child class contains an array of
- * Pre_Operation object
- */
-class Pre_operation_detail
-{
- var $operation;
- function __construct($p_cn,$p_id=0)
- {
- $this->db=$p_cn;
- $this->operation=new Pre_operation($this->db);
- $this->valid=array('ledger'=>'jrn_def_id','ledger_type'=>'jrn_type','direct'=>'od_direct');
- $this->jrn_def_id=-1;
- }
-
-
/*!\brief show a form to use pre_op
- */
+ */
function form_get ($p_url)
{
- $r=HtmlInput::button_action(_("Modèle d'opérations"), ' $(\'modele_op_div\').style.display=\'block\';if ( $(\'lk_modele_op_tab\')) { $(\'lk_modele_op_tab\').focus();}');
+ $r=HtmlInput::button_action(_("Modèle d'opérations"),
+ ' $(\'modele_op_div\').style.display=\'block\';if ( $(\'lk_modele_op_tab\')) { $(\'lk_modele_op_tab\').focus();}');
$r.='
';
return $r;
}
- /*!\brief count the number of pred operation for a ledger */
- function count()
- {
- $a=$this->db->count_sql("select od_id,od_name from op_predef ".
- " where jrn_def_id=".$this->jrn_def_id.
- " and od_direct ='".$this->od_direct."'".
- " order by od_name");
- return $a;
- }
+
/*!\brief show the button for selecting a predefined operation */
- function show_button($p_url)
+ function display_list_operation($p_url)
{
-
-
+
+
$value=$this->db->get_array("select od_id,od_name,od_description from op_predef ".
- " where jrn_def_id=$1".
- " and od_direct =$2".
- " order by od_name",
- array($this->jrn_def_id,$this->od_direct ));
-
- if ( $this->jrn_def_id=='') $value=array();
-
+ " where jrn_def_id=$1".
+ " and od_direct =$2".
+ " order by od_name",
+ array($this->p_jrn,$this->od_direct ));
+
+ if ( $this->p_jrn=='') $value=array();
+
$r="";
if (count($value)==0) {
$r.=_("Vous n'avez encore sauvé aucun modèle");
@@ -292,7 +348,7 @@ class Pre_operation_detail
$r.='