type = 'VEN';
}
/* !\brief verify that the data are correct before inserting or confirming
* \param an array (usually $_POST)
* \return String
* \throw Exception if an error occurs
*/
public function verify($p_array) {
global $g_parameter, $g_user;
if (is_array($p_array ) == false || empty($p_array))
throw new Exception ("Array empty");
extract($p_array);
/*
* Check needed value
*/
check_parameter($p_array,'p_jrn,e_date,e_client');
/* check for a double reload */
if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0)
throw new Exception(_('Double Encodage'), 5);
/* check if we can write into this ledger */
if ($g_user->check_jrn($p_jrn) != 'W')
throw new Exception(_('Accès interdit'), 20);
/* check if there is a customer */
if (strlen(trim($e_client)) == 0)
throw new Exception(_('Vous n\'avez pas donné de client'), 11);
/* check if the date is valid */
if (isDate($e_date) == null) {
throw new Exception(_('Date invalide'), 2);
}
$oPeriode = new Periode($this->db);
if ($this->check_periode() == true) {
$tperiode = $period;
/* check that the datum is in the choosen periode */
$oPeriode->p_id = $period;
list ($min, $max) = $oPeriode->get_date_limit();
if (cmpDate($e_date, $min) < 0 ||
cmpDate($e_date, $max) > 0)
throw new Exception(_('Date et periode ne correspondent pas'), 6);
}
else {
$per = new Periode($this->db);
$tperiode = $per->find_periode($e_date);
}
/* check if the periode is closed */
if ($this->is_closed($tperiode) == 1) {
throw new Exception(_('Periode fermee'), 6);
}
/* check if we are using the strict mode */
if ($this->check_strict() == true) {
/* if we use the strict mode, we get the date of the last
operation */
$last_date = $this->get_last_date();
if ($last_date != null && cmpDate($e_date, $last_date) < 0)
throw new Exception(_('Vous utilisez le mode strict la dernière operation est date du ')
. $last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 13);
}
$fiche = new Fiche($this->db);
$fiche->get_by_qcode($e_client);
if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
throw new Exception(_('La fiche ') . $e_client . _('n\'a pas de poste comptable'), 8);
/* get the account and explode if necessary */
$sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
// if 2 accounts, take only the debit one for customer
if (strpos($sposte, ',') != 0) {
$array = explode(',', $sposte);
$poste_val = $array[0];
} else {
$poste_val = $sposte;
}
/* The account exists */
$poste = new Acc_Account_Ledger($this->db, $poste_val);
if ($poste->load() == false) {
throw new Exception(_('Pour la fiche ') . $e_client . _(' le poste comptable [') . $poste->id . _('] n\'existe pas'), 9);
}
/* Check if the card belong to the ledger */
$fiche = new Fiche($this->db);
$fiche->get_by_qcode($e_client, 'deb');
if ($fiche->belong_ledger($p_jrn) != 1)
throw new Exception(_('La fiche ') . $e_client . _('n\'est pas accessible à ce journal'), 10);
$nb = 0;
//----------------------------------------
// foreach item
//----------------------------------------
for ($i = 0; $i < $nb_item; $i++) {
if (strlen(trim(${'e_march' . $i})) == 0)
continue;
/* check if amount are numeric and */
if (isNumber(${'e_march' . $i . '_price'}) == 0)
throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un montant invalide [') . ${'e_march' . $i} . ']', 6);
if (isNumber(${'e_quant' . $i}) == 0)
throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a une quantité invalide [') . ${'e_quant' . $i} . ']', 7);
/* check if all card has a ATTR_DEF_ACCOUNT */
$fiche = new Fiche($this->db);
$fiche->get_by_qcode(${'e_march' . $i});
if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'a pas de poste comptable'), 8);
// Check if the given tva id is valid
if ($g_parameter->MY_TVA_USE == 'Y') {
if (isNumber(${'e_march' . $i . '_tva_id'}) == 0)
throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
$tva_rate = new Acc_Tva($this->db);
$tva_rate->set_parameter('id', ${'e_march' . $i . '_tva_id'});
if ($tva_rate->load() != 0)
throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
/*
* check if the accounting for VAT are valid
*/
$a_poste = explode(',', $tva_rate->tva_poste);
if (
$this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1', array($a_poste[0])) == 0 ||
$this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1', array($a_poste[1])) == 0)
throw new Exception(_(" La TVA " . $tva_rate->tva_label . " utilise des postes comptables inexistants"));
}
// if 2 accounts, take only the credit one
/* The account exists */
$sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
if (strpos($sposte, ',') != 0) {
$array = explode(',', $sposte);
$poste_val = $array[1];
} else {
$poste_val = $sposte;
}
$poste = new Acc_Account_Ledger($this->db, $poste_val);
if ($poste->load() == false) {
throw new Exception(_('Pour la fiche ') . ${'e_march' . $i} . _(' le poste comptable [') . $poste->id . _('n\'existe pas'), 9);
}
/* Check if the card belong to the ledger */
$fiche = new Fiche($this->db);
$fiche->get_by_qcode(${'e_march' . $i});
if ($fiche->belong_ledger($p_jrn, 'cred') != 1)
throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'est pas accessible à ce journal'), 10);
$nb++;
}
if ($nb == 0)
throw new Exception(_('Il n\'y a aucune marchandise'), 12);
//------------------------------------------------------
// The "Paid By" check
//------------------------------------------------------
if ($e_mp != 0) {
$this->check_payment($e_mp, ${"e_mp_qcode_" . $e_mp});
}
}
/* !\brief insert into the database, it calls first the verify function,
* change the value of this->jr_id and this->jr_internal
* * It generates the document if gen_invoice is set and save the middle of payment if any ($e_mp)
*
* \param $p_array is usually $_POST or a predefined operation
* \return string
* \note throw an Exception
*/
public function insert($p_array = null) {
global $g_parameter;
extract($p_array);
$this->verify($p_array);
$group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
$seq = $this->db->get_next_seq('s_grpt');
$this->id = $p_jrn;
$internal = $this->compute_internal_code($seq);
$this->internal = $internal;
$oPeriode = new Periode($this->db);
$check_periode = $this->check_periode();
if ($check_periode == true)
$tperiode = $period;
else
$tperiode = $oPeriode->find_periode($e_date);
$cust = new Fiche($this->db);
$cust->get_by_qcode($e_client);
$sposte = $cust->strAttribut(ATTR_DEF_ACCOUNT);
// if 2 accounts, take only the debit one for the customer
//
if (strpos($sposte, ',') != 0) {
$array = explode(',', $sposte);
$poste = $array[0];
} else {
$poste = $sposte;
}
bcscale(4);
try {
$tot_amount = 0;
$tot_tva = 0;
$tot_debit = 0;
$this->db->start();
$tva = array();
/* Save all the items without vat */
for ($i = 0; $i < $nb_item; $i++) {
$n_both = 0;
if (strlen(trim(${'e_march' . $i})) == 0)
continue;
/* First we save all the items without vat */
$fiche = new Fiche($this->db);
$fiche->get_by_qcode(${"e_march" . $i});
$amount = bcmul(${'e_march' . $i . '_price'}, ${'e_quant' . $i});
$tot_amount = round(bcadd($tot_amount, $amount),2);
$acc_operation = new Acc_Operation($this->db);
$acc_operation->date = $e_date;
$sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
// if 2 accounts, take only the credit one
if (strpos($sposte, ',') != 0) {
$array = explode(',', $sposte);
$poste_val = $array[1];
} else {
$poste_val = $sposte;
}
$acc_operation->poste = $poste_val;
$acc_operation->amount = $amount;
$acc_operation->grpt = $seq;
$acc_operation->jrn = $p_jrn;
$acc_operation->type = 'c';
$acc_operation->periode = $tperiode;
if ($g_parameter->MY_UPDLAB == 'Y')
$acc_operation->desc = strip_tags(${"e_march" . $i . "_label"});
else
$acc_operation->desc = null;
$acc_operation->qcode = ${"e_march" . $i};
if ($amount < 0)
$tot_debit = bcadd($tot_debit, abs($amount));
$j_id = $acc_operation->insert_jrnx();
if ($g_parameter->MY_TVA_USE == 'Y') {
/* Compute sum vat */
$oTva = new Acc_Tva($this->db);
$idx_tva = ${'e_march' . $i . '_tva_id'};
$tva_item = ${'e_march' . $i . '_tva_amount'};
$oTva->set_parameter("id", $idx_tva);
$oTva->load();
/* if empty then we need to compute it */
if (trim($tva_item) == '' || ${'e_march'.$i.'_tva_amount'} == 0) {
/* retrieve tva */
$l = new Acc_Tva($this->db, $idx_tva);
$l->load();
$tva_item = bcmul($amount, $l->get_parameter('rate'));
}
if (isset($tva[$idx_tva]))
$tva[$idx_tva]+=$tva_item;
else
$tva[$idx_tva] = $tva_item;
if ($oTva->get_parameter("both_side") == 0) {
$tot_tva = round(bcadd($tva_item, $tot_tva), 2);
} else {
$n_both = $tva_item;
if ($n_both < 0)
$tot_debit = bcadd($tot_debit, abs($n_both));
}
}
/* Save the stock */
/* if the quantity is < 0 then the stock increase (return of
* material)
*/
$nNeg = (${"e_quant" . $i} < 0) ? -1 : 1;
// always save quantity but in withStock we can find
// what card need a stock management
if ($g_parameter->MY_STOCK = 'Y' && isset($repo))
{
$dir=(${'e_quant'.$i} < 0 ) ? 'd':'c';
Stock_Goods::insert_goods($this->db, array('j_id' => $j_id, 'goods' => ${'e_march' . $i}, 'quant' => $nNeg * ${'e_quant' . $i}, 'dir' => $dir, 'repo' => $repo));
}
if ($g_parameter->MY_ANALYTIC != "nu") {
// for each item, insert into operation_analytique */
$op = new Anc_Operation($this->db);
$op->oa_group = $group;
$op->j_id = $j_id;
$op->oa_date = $e_date;
$op->oa_debit = 'f';
$op->oa_description = sql_string($e_comm);
$op->save_form_plan($_POST, $i, $j_id);
}
if ($g_parameter->MY_TVA_USE == 'Y') {
/* save into quant_sold */
$r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9)", array(null, /* 1 */
$j_id, /* 2 */
${'e_march' . $i}, /* 3 */
${'e_quant' . $i}, /* 4 */
round($amount, 2), /* 5 */
$tva_item, /* 6 */
$idx_tva, /* 7 */
$e_client, /* 8 */
$n_both));
} else {
$r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9) ", array(null, /* 1 */
$j_id, /* 2 */
${'e_march' . $i}, /* 3 */
${'e_quant' . $i}, /* 4 */
$amount, // 5
0,
null,
$e_client,
0));
} // if ( $g_parameter->MY_TVA_USE=='Y') {
}// end loop : save all items
/* save total customer */
$cust_amount = bcadd($tot_amount, $tot_tva);
$acc_operation = new Acc_Operation($this->db);
$acc_operation->date = $e_date;
$acc_operation->poste = $poste;
$acc_operation->amount = $cust_amount;
$acc_operation->grpt = $seq;
$acc_operation->jrn = $p_jrn;
$acc_operation->type = 'd';
$acc_operation->periode = $tperiode;
$acc_operation->qcode = ${"e_client"};
if ($cust_amount > 0)
$tot_debit = bcadd($tot_debit, $cust_amount);
$let_tiers = $acc_operation->insert_jrnx();
/** save all vat
* $i contains the tva_id and value contains the vat amount
* if if ($g_parameter->MY_TVA_USE == 'Y' )
*/
if ($g_parameter->MY_TVA_USE == 'Y') {
foreach ($tva as $i => $value) {
$oTva = new Acc_Tva($this->db);
$oTva->set_parameter('id', $i);
$oTva->load();
$poste_vat = $oTva->get_side('c');
$cust_amount = bcadd($tot_amount, $tot_tva);
$acc_operation = new Acc_Operation($this->db);
$acc_operation->date = $e_date;
$acc_operation->poste = $poste_vat;
$acc_operation->amount = $value;
$acc_operation->grpt = $seq;
$acc_operation->jrn = $p_jrn;
$acc_operation->type = 'c';
$acc_operation->periode = $tperiode;
if ($value < 0)
$tot_debit = bcadd($tot_debit, abs($value));
$acc_operation->insert_jrnx();
// if TVA is on both side, we deduce it immediately
if ($oTva->get_parameter("both_side") == 1) {
$poste_vat = $oTva->get_side('d');
$cust_amount = bcadd($tot_amount, $tot_tva);
$acc_operation = new Acc_Operation($this->db);
$acc_operation->date = $e_date;
$acc_operation->poste = $poste_vat;
$acc_operation->amount = $value;
$acc_operation->grpt = $seq;
$acc_operation->jrn = $p_jrn;
$acc_operation->type = 'd';
$acc_operation->periode = $tperiode;
$acc_operation->insert_jrnx();
$tot_debit = bcadd($tot_debit, $value);
$n_both = $value;
}
}
} // if ($g_parameter->MY_TVA_USE=='Y')
/* insert into jrn */
$acc_operation = new Acc_Operation($this->db);
$acc_operation->date = $e_date;
$acc_operation->echeance = $e_ech;
$acc_operation->amount = abs(round($tot_debit, 2));
$acc_operation->desc = $e_comm;
$acc_operation->grpt = $seq;
$acc_operation->jrn = $p_jrn;
$acc_operation->periode = $tperiode;
$acc_operation->pj = $e_pj;
$acc_operation->mt = $mt;
$this->jr_id = $acc_operation->insert_jrn();
$this->pj = $acc_operation->set_pj();
/* * = e_pj then do not increment sequence */
/* and e_pj is not null */
if (strcmp($e_pj, $e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0) {
$this->inc_seq_pj();
}
$this->db->exec_sql("update jrn set jr_internal='" . $internal . "' where " .
" jr_grpt_id = " . $seq);
/* update quant_sold */
$this->db->exec_sql('update quant_sold set qs_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)', array($internal, $seq));
/* Save the attachment or generate doc */
if (isset($_FILES['pj'])) {
if (strlen(trim($_FILES['pj']['name'])) != 0)
$this->db->save_upload_document($seq);
else
/* Generate an invoice and save it into the database */
if (isset($_POST['gen_invoice'])) {
$file = $this->create_document($internal, $p_array);
$this->doc='' . $file . '';
}
}
//----------------------------------------
// Save the payer
//----------------------------------------
if ($e_mp != 0) {
/* mp */
$mp = new Acc_Payment($this->db, $e_mp);
$mp->load();
/* fiche */
$fqcode = ${'e_mp_qcode_' . $e_mp};
$acfiche = new Fiche($this->db);
$acfiche->get_by_qcode($fqcode);
/* jrnx */
$acseq = $this->db->get_next_seq('s_grpt');
$acjrn = new Acc_Ledger($this->db, $mp->get_parameter('ledger_target'));
$acinternal = $acjrn->compute_internal_code($acseq);
/* Insert paid by */
$acc_pay = new Acc_Operation($this->db);
$acc_pay->date = $e_date;
/* get the account and explode if necessary */
$sposte = $acfiche->strAttribut(ATTR_DEF_ACCOUNT);
// if 2 accounts, take only the debit one for customer
if (strpos($sposte, ',') != 0) {
$array = explode(',', $sposte);
$poste_val = $array[0];
} else {
$poste_val = $sposte;
}
$famount = bcsub($cust_amount, $acompte);
$acc_pay->poste = $poste_val;
$acc_pay->qcode = $fqcode;
$acc_pay->amount = abs(round($famount, 2));
$acc_pay->desc = null;
$acc_pay->grpt = $acseq;
$acc_pay->jrn = $mp->get_parameter('ledger_target');
$acc_pay->periode = $tperiode;
$acc_pay->type = ($famount >= 0) ? 'd' : 'c';
$acc_pay->insert_jrnx();
/* Insert supplier */
$acc_pay = new Acc_Operation($this->db);
$acc_pay->date = $e_date;
$acc_pay->poste = $poste;
$acc_pay->qcode = $e_client;
$acc_pay->amount = abs(round($famount, 2));
$acc_pay->desc = null;
$acc_pay->grpt = $acseq;
$acc_pay->jrn = $mp->get_parameter('ledger_target');
$acc_pay->periode = $tperiode;
$acc_pay->type = ($famount >= 0) ? 'c' : 'd';
$let_other = $acc_pay->insert_jrnx();
/* insert into jrn */
$acc_pay->mt = $mt;
$acjrn->grpt_id = $acseq;
$acc_pay->desc = (!isset($e_comm_paiement) || strlen(trim($e_comm_paiement)) == 0) ? $e_comm : $e_comm_paiement;
$mp_jr_id = $acc_pay->insert_jrn();
$acjrn->update_internal_code($acinternal);
$r1 = $this->get_id($internal);
$r2 = $this->get_id($acinternal);
/*
* add lettering
*/
$oletter = new Lettering($this->db);
$oletter->insert_couple($let_tiers, $let_other);
/* set the flag paid */
$Res = $this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1", array($r1));
/* Reconcialiation */
$rec = new Acc_Reconciliation($this->db);
$rec->set_jr_id($r1);
$rec->insert($r2);
/*
* save also into quant_fin
*/
/* get ledger property */
$ledger = new Acc_Ledger_Fin($this->db, $acc_pay->jrn);
$prop = $ledger->get_propertie();
/* if ledger is FIN then insert into quant_fin */
if ($prop['jrn_def_type'] == 'FIN') {
$ledger->insert_quant_fin($acfiche->id, $mp_jr_id, $cust->id, bcmul($famount, 1));
}
}
} catch (Exception $e) {
echo '' .
'Erreur dans l\'enregistrement ' .
__FILE__ . ':' . __LINE__ . ' ' .
$e->getMessage();
echo $e->getTrace();
$this->db->rollback();
throw new Exception ($e);
}
$this->db->commit();
return $internal;
}
/* !
* @brief show the summary of the operation and propose to save it
* @param array contains normally $_POST. It proposes also to save
* the Analytic accountancy
* @param $p_summary false for the feedback, true to show the summary
* @return string
*
*/
function confirm($p_array, $p_summary = false) {
global $g_parameter;
extract($p_array);
// don't need to verify for a summary
if (!$p_summary)
$this->verify($p_array);
$anc = null;
// to show a select list for the analytic & VAT USE
// if analytic is op (optionnel) there is a blank line
bcscale(4);
$client = new Fiche($this->db);
$client->get_by_qcode($e_client, true);
$client_name = $client->getName() .
' ' . $client->strAttribut(ATTR_DEF_ADRESS) . ' ' .
$client->strAttribut(ATTR_DEF_CP) . ' ' .
$client->strAttribut(ATTR_DEF_CITY);
$lPeriode = new Periode($this->db);
if ($this->check_periode() == true) {
$lPeriode->p_id = $period;
} else {
$lPeriode->find_periode($e_date);
}
$date_limit = $lPeriode->get_date_limit();
$r = "";
$r.=' ';
$r.='';
if ( $p_summary ) {
$jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->internal));
$r.="
';
$r.='";
$r.=' ";
}
$r.='';
$r.=_('Détail opération ');
$r.=' ';
$r.='';
$r.=sprintf ('%s',
$jr_id,dossier::id(),$this->internal);
$r.=' ';
$r.="';
if ( ! $p_summary) {
$r.=' ';
$r.='' . _('Numéro Pièce') .' '. hb($e_pj) . ' ';
} else {
if ( strcmp($this->pj,$e_pj) != 0 )
{
$r.='' . _('Numéro Pièce') .' '. hb($this->pj) .
' '._('Attention numéro pièce existante, elle a du être adaptée').' ';
} else {
$r.='' . _('Numéro Pièce') .' '. hb($this->pj) . ' ';
}
}
$r.='';
$r.=' ';
$r.=' ' . _('Date') . ' ' . hb($e_date) . ' ';
$r.='';
$r.=' ';
$r.='' . _('Echeance') . ' ' . hb($e_ech) . ' ';
$r.='';
$r.=' ';
$r.=' ' . _('Période Comptable') . ' ' .hb( $date_limit['p_start'] . '-' . $date_limit['p_end']) . ' ';
$r.='';
$r.=' ';
$r.=' ' . _('Journal') . ' ' . hb($this->get_name()) . ' ';
$r.='';
$r.=' ';
$r.=' ' . _('Libellé') . ' ' . hb($e_comm) . ' ';
$r.='';
$r.=' ';
$r.=' ' . _('Client') . ' ' . hb($e_client . ':' . $client_name) . ' ';
$r.='' . _('Détail articles vendus') . '
';
$r.='';
$r.='
';
$r.='';
$r.=" ';
$tot_amount = 0.0;
$tot_tva = 0.0;
for ($i = 0; $i < $nb_item; $i++) {
if (strlen(trim(${"e_march" . $i})) == 0)
continue;
/* retrieve information for card */
$fiche = new Fiche($this->db);
$fiche->get_by_qcode(${"e_march" . $i});
if ($g_parameter->MY_UPDLAB == 'Y')
$fiche_name = h(${"e_march" . $i . "_label"});
else
$fiche_name = $fiche->strAttribut(ATTR_DEF_NAME);
if ($g_parameter->MY_TVA_USE == 'Y') {
$oTva = new Acc_Tva($this->db);
$idx_tva = ${"e_march" . $i . "_tva_id"};
$oTva->set_parameter('id', $idx_tva);
$oTva->load();
}
$op = new Acc_Compute();
$amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i});
$op->set_parameter("amount", $amount);
if ($g_parameter->MY_TVA_USE == 'Y') {
$op->set_parameter('amount_vat_rate', $oTva->get_parameter('rate'));
$op->compute_vat();
$tva_computed = $op->get_parameter('amount_vat');
$tva_item = ${"e_march" . $i . "_tva_amount"};
if (isset($tva[$idx_tva]))
$tva[$idx_tva]+=$tva_item;
else
$tva[$idx_tva] = $tva_item;
$tot_tva = round(bcadd($tva_item, $tot_tva), 2);
}
$tot_amount = round(bcadd($tot_amount, $amount), 2);
$r.='" . _('Code') . " ";
$r.="" . _('Dénomination') . " ";
$r.="" . _('prix') . " ";
$r.="" . _('quantité') . " ";
if ($g_parameter->MY_TVA_USE == 'Y') {
$r.="" . _('tva') . " ";
$r.=' ' . _('Montant TVA') . ' ';
$r.='' . _('Montant HTVA') . ' ';
$r.='' . _('Montant TVAC') . ' ';
} else {
$r.='' . _('Montant') . ' ';
}
/* 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.='';
$r.=' ';
} // end loop item
//
// Add the sum
$decalage=($g_parameter->MY_TVA_USE == 'Y')?'';
$r.=${"e_march" . $i};
$r.=' ';
$r.='';
$r.=$fiche_name;
$r.=' ';
$r.='';
$r.=nbm(${"e_march" . $i . "_price"});
$r.=' ';
$r.='';
$r.=nbm(${"e_quant" . $i});
$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.='';
$r.=HtmlInput::infobulle(28);
$r.=''
. nbm($tva_item) . '';
} else {
$r.=' ';
$r.=nbm($tva_item);
}
$r.=' ';
$r.='';
$r.=nbm($amount);
$r.=' ';
$tot_row = bcadd($tva_item, $amount);
$r.=td(nbm($tot_row), 'class="num"');
} else {
$r.='';
$r.=nbm($amount);
$r.=' ';
}
// encode the pa
if ($g_parameter->MY_ANALYTIC != 'nu') { // 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, $amount);
$r.=' ';
}
$r.='':' ';
$tot = round(bcadd($tot_amount, $tot_tva), 2);
$tot_tva=nbm($tot_tva);
$tot=nbm($tot);
$str_tot=_('Totaux');
$tot_amount=nbm($tot_amount);
$r.=<<
{$str_tot}
{$tot_tva}
{$tot_amount}
{$tot}
EOF;
$r.='
Total HTVA | '; $r.=td(hb($tot_amount ),'class="num"'); foreach ($tva as $i => $value) { $oTva->set_parameter('id', $i); $oTva->load(); $r.='
TVA ' . $oTva->get_parameter('label').' | '; $r.=td(hb(nbm($tva[$i])),'class="num"'); } $r.='
' . _('Déduction acompte ') . h($acompte) . '
' . _('Libellé :') . h($e_comm_paiement) ; $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'");
$r.=$doc_gen->input() . '
';
}
$r.='
';
$obj = new IText();
$r.=_('Numero de bon de commande : ') . $obj->input('bon_comm') . '
';
$r.=_('Autre information : ') . $obj->input('other_info') . '
';
$r.='