';
}
/* if we use the AC */
if ($g_parameter->MY_ANALYTIC != 'nu') {
$anc = new Anc_Plan($this->db);
$a_anc = $anc->get_list();
$x = count($a_anc);
/* set the width of the col */
$r.='
' . _('Compt. Analytique') . '
';
/* add hidden variables pa[] to hold the value of pa_id */
$r.=Anc_Plan::hidden($a_anc);
}
$r.='
';
$both_side=0;
if ($g_parameter->MY_TVA_USE == 'Y') {
$r.='
';
$r.=$oTva->get_parameter('label');
$r.='
';
$both_side=$oTva->get_parameter("both_side");
/* warning if tva_computed and given are not the
same */
if (bcsub($tva_item, $tva_computed) != 0 && ! ($tva_item == 0 && $both_side == 1)) {
$r.='
';
}
// encode the pa
if ($g_parameter->MY_ANALYTIC != 'nu'
&& $g_parameter->match_analytic($fiche->strAttribut(ATTR_DEF_ACCOUNT))==TRUE) { // use of AA
// show form
$anc_op = new Anc_Operation($this->db);
$null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 : 0;
$r.='
';
$p_mode = ($p_summary == false) ? 1 : 0;
$p_array['pa_id'] = $a_anc;
/* op is the operation it contains either a sequence or a jrnx.j_id */
$r.=HtmlInput::hidden('op[]=', $i);
$r.=$anc_op->display_form_plan($p_array, $null, $p_mode, $i, round($amount,2));
$r.='
';
}
$r.='
';
} // end loop item
//
// Add the sum
$decalage=($g_parameter->MY_TVA_USE == 'Y')?'
'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
}
if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
$r.=' Total '.hb($tot);
}
$r.='';
/* Add hidden */
$r.=HtmlInput::hidden('e_client', $e_client);
$r.=HtmlInput::hidden('nb_item', $nb_item);
$r.=HtmlInput::hidden('p_jrn', $p_jrn);
$r.=HtmlInput::hidden('jrn_note_input',h($p_array['jrn_note_input']));
$mt = microtime(true);
$r.=HtmlInput::hidden('mt', $mt);
$r.=HtmlInput::post_to_hidden(['p_currency_rate','p_currency_code']);
if (isset($period))
{
$r.=HtmlInput::hidden('period', $period);
}
/* \todo comment les types hidden gérent ils des contenus avec des quotes, double quote ou < > ??? */
$r.=HtmlInput::hidden('e_comm', $e_comm);
$r.=HtmlInput::hidden('e_date', $e_date);
$r.=HtmlInput::hidden('e_ech', $e_ech);
$r.=HtmlInput::hidden('e_pj', $e_pj);
$r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
if ( $this->has_other_tax() && isset($p_array["other_tax"])) {
$r.=HtmlInput::hidden("other_tax",$p_array['other_tax']);
$r.=HtmlInput::hidden("other_tax_amount",$p_array['other_tax_amount']);
}
$e_mp = (isset($e_mp)) ? $e_mp : 0;
$r.=HtmlInput::hidden('e_mp', $e_mp);
if ( isset($repo) ) {
// Show the available repository
$r.= $this->select_depot($p_summary,$repo);
}
/* if the paymethod is not 0 and if a quick code is given */
if ($e_mp != 0 && noalyss_strlentrim(${'e_mp_qcode_' . $e_mp}) != 0) {
$r.=HtmlInput::hidden('e_mp_qcode_' . $e_mp, ${'e_mp_qcode_' . $e_mp});
$r.=HtmlInput::hidden('acompte', $acompte);
$r.=HtmlInput::hidden('e_comm_paiement', $e_comm_paiement);
/* needed for generating a invoice */
$r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
$r.=HtmlInput::hidden('mp_date', ${'mp_date'});
$fname = new Fiche($this->db);
$fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
$r.='
' . "Payé par " . ${'e_mp_qcode_' . $e_mp} .
" le ".${"mp_date"}.
" " . $fname->getName() . '
' . '
' . _('Déduction acompte ') . h($acompte) . '
' .
_('Libellé :') . h($e_comm_paiement) ;
$r.=' ';
}
$r.=HtmlInput::hidden('jrn_type', $jrn_type);
for ($i = 0; $i < $nb_item; $i++) {
$r.=HtmlInput::hidden("e_march" . $i, ${"e_march" . $i});
if (isset(${"e_march" . $i . "_label"}))
$r.=HtmlInput::hidden("e_march" . $i . "_label", ${"e_march" . $i . "_label"});
$r.=HtmlInput::hidden("e_march" . $i . "_price", ${"e_march" . $i . "_price"});
if ($g_parameter->MY_TVA_USE == 'Y') {
$r.=HtmlInput::hidden("e_march" . $i . "_tva_id", ${"e_march" . $i . "_tva_id"});
$r.=HtmlInput::hidden("e_march" . $i . "_tva_amount", ${"e_march" . $i . "_tva_amount"});
}
$r.=HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i});
}
/*
* warning if the amount is positive and expecting a negative one
*/
$negative=$this->display_negative_warning($tot);
if ( $negative != "") {
$r.=span($negative,'class="warning" ');
}
return $r;
}
/*!\brief the function extra info allows to
* - add a attachment
* - generate an invoice
* - insert extra info
* \return string
*/
public function extra_info() {
$r = '
';
// check for upload piece
$file = new IFile();
$file->table = 0;
$file->setAlertOnSize(true);
$r.='
';
$r.=_("Ajoutez une pièce justificative ");
$r.=$file->input("pj", "");
if ($this->db->count_sql("select md_id,md_name from document_modele where md_affect='VEN' ") > 0) {
$r.=_('ou générer une facture') . ' ';
// We propose to generate the invoice and some template
$doc_gen = new ISelect();
$doc_gen->name = "gen_doc";
$doc_gen->value = $this->db->make_array(
"select md_id,md_name " .
" from document_modele where md_affect='VEN' order by 2");
$r.=$doc_gen->input() . ' ';
}
$r.=' ';
$obj = new IText();
$r.=_('Numero de bon de commande : ') . $obj->input('bon_comm') . ' ';
$r.=_('Communication ou autre information : ') . $obj->input('other_info') . ' ';
$r.='
';
$r.='
';
return $r;
}
/*!\brief display the form for entering data for invoice,
* \param $p_array is null or you can put the predef operation or the $_POST
*
* \return HTML string
*/
function input($p_array = null, $p_readonly = 0) {
global $g_parameter, $g_user;
// load ledger definition
$this->load();
$http=new HttpInput();
$http->set_array([]);
if ($p_array != null) {
extract($p_array, EXTR_SKIP);
$http->set_array($p_array);
}
if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
$flag_tva = $g_parameter->MY_TVA_USE;
/* Add button */
$str_add_button_tiers = "";
$add_card=FALSE;
if ($g_user->check_action(FICADD) == 1) {
$add_card=TRUE;
$str_add_button_tiers = $this->add_card("deb", "e_client");
}
// The first day of the periode
$oPeriode = new Periode($this->db);
list ($l_date_start, $l_date_end) = $oPeriode->get_date_limit($g_user->get_periode());
if ($g_parameter->MY_DATE_SUGGEST == 'Y')
$op_date = (!isset($e_date) ) ? $l_date_start : $e_date;
else
$op_date = (!isset($e_date) ) ? '' : $e_date;
$e_ech = (isset($e_ech)) ? $e_ech : "";
$e_comm = (isset($e_comm)) ? $e_comm : "";
$r = '';
$r.=dossier::hidden();
$f_legend = _('Client');
$Echeance = new IDate();
$Echeance->setReadOnly(false);
$Echeance->tabindex = 2;
$label = Icon_Action::infobulle(4);
$f_echeance = $Echeance->input('e_ech', $e_ech, _('Echéance') . $label);
$Date = new IDate();
$Date->setReadOnly(false);
$f_date = $Date->input("e_date", $op_date);
$f_periode = '';
// Periode
//--
if ($this->check_periode() == true) {
$l_user_per = $g_user->get_periode();
$def = (isset($periode)) ? $periode : $l_user_per;
$period = new IPeriod("period");
$period->user = $g_user;
$period->cn = $this->db;
$period->value = $def;
$period->type = OPEN;
try {
$l_form_per = $period->input();
} catch (Exception $e) {
if ($e->getCode() == 1) {
throw new Exception( _("Aucune période ouverte") );
}
}
$label = Icon_Action::infobulle(3);
$f_periode = '
' . _("Période comptable") . "
$label " . $l_form_per . '
';
}
/* if we suggest the next pj, then we need a javascript */
$add_js = "";
if ($g_parameter->MY_PJ_SUGGEST != 'N') {
$add_js = "update_pj();";
}
if ($g_parameter->MY_DATE_SUGGEST == 'Y') {
$add_js.='get_last_date();';
}
$add_js.='update_name();';
$add_js.='update_pay_method();';
$add_js.='update_row("sold_item");';
$add_js.='update_other_tax();';
$add_js.='update_visibility_quantity();';
$wLedger = $this->select_ledger('VEN', 2,FALSE);
if ($wLedger == null)
throw new Exception(_('Pas de journal disponible'));
$wLedger->table = 0;
$wLedger->javascript = "onChange='update_predef(\"ven\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
$wLedger->label = " Journal " . Icon_Action::infobulle(2);
$f_jrn = $wLedger->input();
$Commentaire = new IText();
$Commentaire->table = 0;
$Commentaire->setReadOnly(false);
$Commentaire->size = (empty($e_comm))?60:strlen($e_comm)+5;
$Commentaire->size = ($Commentaire->size<60)?60:$Commentaire->size;
$Commentaire->tabindex = 3;
$label = Icon_Action::infobulle(1);
$f_desc = $Commentaire->input("e_comm", $e_comm) ;
// PJ
//--
/* suggest PJ ? */
$default_pj = '';
if ($g_parameter->MY_PJ_SUGGEST != 'N') {
$default_pj = $this->guess_pj();
}
$pj = new IText();
if ( $g_parameter->MY_PJ_SUGGEST=='A'||$g_user->check_action(UPDRECEIPT)==0)
{
$pj->setReadOnly(true);
$pj->id="e_pj";
}
$pj->table = 0;
$pj->name = "e_pj";
$pj->size = 10;
$pj->value = (isset($e_pj)) ? $e_pj : $default_pj;
$f_pj = $pj->input() . HtmlInput::hidden('e_pj_suggest', $default_pj);
// Display the customer
//--
$fiche = 'deb';
// Save old value and set a new one
//--
$e_client = ( isset($e_client) ) ? $e_client : "";
$e_client_label = " "; //str_pad("",100,".");
// retrieve e_client_label
//--
if (noalyss_strlentrim($e_client) != 0) {
$fClient = new Fiche($this->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) . ' ';
}
$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', 'deb');
// 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
$Hid = new IHidden();
$p_article = ( isset($nb_item)) ? $nb_item : $this->get_min_row();
$r.=$Hid->input("nb_item", $p_article);
$p_article = ($p_article < $this->get_min_row()) ? $this->get_min_row() : $p_article;
$f_legend_detail = _("Détail articles vendus");
// For each article
//--
for ($i = 0; $i < $p_article; $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"} : "" ;
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_label = (isset(${"e_march" . $i . "_label"})) ? ${"e_march" . $i . "_label"} : "";
// retrieve the tva label and name
//--
if (noalyss_strlentrim($march) != 0 && noalyss_strlentrim($march_label) == 0) {
$fMarch = new Fiche($this->db);
$fMarch->get_by_qcode($march);
$march_label = $fMarch->strAttribut(ATTR_DEF_NAME);
if ($flag_tva == 'Y') {
if (!(isset(${"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', 'cred');
$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();
$array[$i]['card_add']=($add_card==TRUE)?$this->add_card("cred", $W1->id):"";
// 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->style='class="input_text label_item"';
} else
{
$Span=new ISpan("e_march".$i."_label");
$Span->extra='class="label_item"';
}
$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->size = 9;
$Price->javascript = "onblur=\"format_number(this,4);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($this->db);
$Tva->in_table = true;
$Tva->set_attribute('compute', $i);
$Tva->set_filter("sale");
$Tva->js = 'onblur="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(${"e_quant$i"})) ? ${"e_quant$i"} : "1";
$Quantity = new INum();
$Quantity->setReadOnly(false);
$Quantity->size = 8;
$Quantity->javascript = "onchange=\"format_number(this,2);clean_tva($i);compute_ledger($i);\"";
$array[$i]['quantity'] = $Quantity->input("e_quant" . $i, $quant);
}// foreach article
$f_type = _('Client');
// Currency
$currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
$currency_select->selected=$http->extract('p_currency_code','string',0);
$currency_input=new INum("p_currency_rate");
$currency_input->id="p_currency_rate";
$currency_input->prec=8;
$currency_input->value=$http->extract('p_currency_rate','string',1);
$currency_input->javascript='onchange="format_number(this,4);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
$currency=new Acc_Currency($this->db,0);
//
// Button for template operation
//
ob_start();
echo '