function Replace($p_tag, $p_array) { global $g_parameter; $p_tag = strtoupper($p_tag); $p_tag = str_replace('=', '', $p_tag); $r = "Tag inconnu"; switch ($p_tag) { case 'DATE': $r = isset($p_array['ag_timestamp']) ? $p_array['ag_timestamp'] : $p_array['e_date']; break; case 'DATE_CALC': $r = ' Date inconnue '; // Date are in $p_array['ag_date'] // or $p_array['e_date'] if (isset($p_array['ag_timestamp'])) { $date = format_date($p_array['ag_timestamp'], 'DD.MM.YYYY', 'YYYY-MM-DD'); $r = $date; } if (isset($p_array['e_date'])) { $date = format_date($p_array['e_date'], 'DD.MM.YYYY', 'YYYY-MM-DD'); $r = $date; } break; // // the company priv // // the company priv case 'MY_NAME': $r = $g_parameter->MY_NAME; break; case 'MY_CP': $r = $g_parameter->MY_CP; break; case 'MY_COMMUNE': $r = $g_parameter->MY_COMMUNE; break; case 'MY_TVA': $r = $g_parameter->MY_TVA; break; case 'MY_STREET': $r = $g_parameter->MY_STREET; break; case 'MY_NUMBER': $r = $g_parameter->MY_NUMBER; break; case 'MY_TEL': $r = $g_parameter->MY_TEL; break; case 'MY_FAX': $r = $g_parameter->MY_FAX; break; case 'MY_PAYS': $r = $g_parameter->MY_PAYS; break; // customer /*\note The CUST_* are retrieved thx the $p_array['tiers'] * which contains the quick_code */ // customer /*\note The CUST_* are retrieved thx the $p_array['tiers'] * which contains the quick_code */ case 'SOLDE': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $p = $tiers->strAttribut(ATTR_DEF_ACCOUNT); $poste = new Acc_Account_Ledger($this->db, $p); $r = $poste->get_solde(' true'); break; case 'CUST_NAME': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_NAME); break; case 'CUST_ADDR_1': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_ADRESS); break; case 'CUST_CP': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_CP); break; case 'CUST_CITY': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_CITY); break; case 'CUST_CO': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_PAYS); break; // Marchandise in $p_array['e_march*'] // \see user_form_achat.php or user_form_ven.php // Marchandise in $p_array['e_march*'] // \see user_form_achat.php or user_form_ven.php case 'CUST_VAT': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_NUMTVA); break; case 'CUST_NUM': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER); break; case 'CUST_BANQUE_NO': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_BQ_NO); break; case 'CUST_BANQUE_NAME': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_BQ_NAME); break; /* -------------------------------------------------------------------------------- */ /* BENEFIT (fee notes */ /* -------------------------------------------------------------------------------- */ /* BENEFIT (fee notes */ case 'BENEF_NAME': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; if ($qcode == '') { $r = ''; break; } $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_NAME); break; case 'BENEF_ADDR_1': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; if ($qcode == '') { $r = ''; break; } $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_ADRESS); break; case 'BENEF_CP': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; if ($qcode == '') { $r = ''; break; } $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_CP); break; case 'BENEF_CITY': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; if ($qcode == '') { $r = ''; break; } $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_CITY); break; case 'BENEF_CO': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; if ($qcode == '') { $r = ''; break; } $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_PAYS); break; // Marchandise in $p_array['e_march*'] // \see user_form_achat.php or user_form_ven.php // Marchandise in $p_array['e_march*'] // \see user_form_achat.php or user_form_ven.php case 'BENEF_VAT': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; if ($qcode == '') { $r = ''; break; } $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_NUMTVA); break; case 'BENEF_NUM': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; if ($qcode == '') { $r = ''; break; } $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER); break; case 'BENEF_BANQUE_NO': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; if ($qcode == '') { $r = ''; break; } $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_BQ_NO); break; case 'BENEF_BANQUE_NAME': $tiers = new Fiche($this->db); $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; if ($qcode == '') { $r = ''; break; } $tiers->get_by_qcode($qcode, false); $r = $tiers->strAttribut(ATTR_DEF_BQ_NAME); break; // Marchandise in $p_array['e_march*'] // \see user_form_achat.php or user_form_ven.php // Marchandise in $p_array['e_march*'] // \see user_form_achat.php or user_form_ven.php case 'NUMBER': $r = $this->d_number; break; case 'USER': return $_SESSION['use_name'] . ', ' . $_SESSION['use_first_name']; break; case 'REFERENCE': $act = new Follow_Up($this->db); $act->ag_id = $this->ag_id; $act->get(); $r = $act->ag_ref; break; /* * - [VEN_ART_NAME] * - [VEN_ART_PRICE] * - [VEN_ART_QUANT] * - [VEN_ART_TVA_CODE] * - [VEN_ART_STOCK_CODE] * - [VEN_HTVA] * - [VEN_TVAC] * - [VEN_TVA] * - [TOTAL_VEN_HTVA] * - [DATE_LIMIT] */ /* * - [VEN_ART_NAME] * - [VEN_ART_PRICE] * - [VEN_ART_QUANT] * - [VEN_ART_TVA_CODE] * - [VEN_ART_STOCK_CODE] * - [VEN_HTVA] * - [VEN_TVAC] * - [VEN_TVA] * - [TOTAL_VEN_HTVA] * - [DATE_LIMIT] */ case 'DATE_LIMIT_CALC': extract($p_array); $id = 'e_ech'; if (!isset(${$id})) { return ""; } $r = format_date(${$id}, 'DD.MM.YYYY', 'YYYY-MM-DD'); break; case 'DATE_LIMIT': extract($p_array); $id = 'e_ech'; if (!isset(${$id})) { return ""; } $r = ${$id}; break; case 'MARCH_NEXT': $this->counter++; $r = ''; break; case 'VEN_ART_NAME': extract($p_array); $id = 'e_march' . $this->counter; // check if the march exists if (!isset(${$id})) { return ""; } // check that something is sold if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0) { $f = new Fiche($this->db); $f->get_by_qcode(${$id}, false); $r = $f->strAttribut(ATTR_DEF_NAME); } else { $r = ""; } break; case 'VEN_ART_LABEL': extract($p_array); $id = 'e_march' . $this->counter . "_label"; // check if the march exists if (!isset(${$id}) || isset(${$id}) && strlen(trim(${$id})) == 0) { $id = 'e_march' . $this->counter; // check if the march exists if (!isset(${$id})) { $r = ""; } else { // check that something is sold if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0) { $f = new Fiche($this->db); $f->get_by_qcode(${$id}, false); $r = $f->strAttribut(ATTR_DEF_NAME); } else { $r = ""; } } } else { $r = ${'e_march' . $this->counter . '_label'}; } break; case 'VEN_ART_STOCK_CODE': extract($p_array); $id = 'e_march' . $this->counter; // check if the march exists if (!isset(${$id})) { $r = ""; } else { // check that something is sold if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0) { $f = new Fiche($this->db); $f->get_by_qcode(${$id}, false); $r = $f->strAttribut(ATTR_DEF_STOCK); $r = $r == NOTFOUND ? '' : $r; } } break; case 'VEN_ART_PRICE': extract($p_array); $id = 'e_march' . $this->counter . '_price'; if (!isset(${$id})) { return ""; } if (${$id} == 0) { return ""; } $r = ${$id}; break; case 'TVA_RATE': case 'VEN_ART_TVA_RATE': extract($p_array); $id = 'e_march' . $this->counter . '_tva_id'; if (!isset(${$id})) { return ""; } if (${$id} == -1 || ${$id} == '') { return ""; } $march_id = 'e_march' . $this->counter . '_price'; if (!isset(${$march_id})) { return ''; } $tva = new Acc_Tva($this->db); $tva->set_parameter("id", ${$id}); if ($tva->load() == -1) { return ''; } return $tva->get_parameter("rate"); break; case 'TVA_CODE': case 'VEN_ART_TVA_CODE': extract($p_array); $id = 'e_march' . $this->counter . '_tva_id'; if (!isset(${$id})) { return ""; } if (${$id} == -1) { return ""; } $qt = 'e_quant' . $this->counter; $price = 'e_march' . $this->counter . '_price'; if (${$price} == 0 || ${$qt} == 0 || strlen(trim($price)) == 0 || strlen(trim($qt)) == 0) { return ""; } $r = ${$id}; break; case 'TVA_LABEL': extract($p_array); $id = 'e_march' . $this->counter . '_tva_id'; if (!isset(${$id})) { return ""; } $march_id = 'e_march' . $this->counter . '_price'; if (!isset(${$march_id})) { return ''; } if (${$march_id} == 0) { return ''; } $tva = new Acc_Tva($this->db, ${$id}); if ($tva->load() == -1) { return ""; } $r = $tva->get_parameter('label'); break; /* total VAT for one sold */ /* total VAT for one sold */ case 'TVA_AMOUNT': case 'VEN_TVA': extract($p_array); $qt = 'e_quant' . $this->counter; $price = 'e_march' . $this->counter . '_price'; $tva = 'e_march' . $this->counter . '_tva_id'; /* if we do not use vat this var. is not set */ if (!isset(${$tva})) { return ''; } if (!isset(${'e_march' . $this->counter})) { return ""; } // check that something is sold if (${$price} == 0 || ${$qt} == 0 || strlen(trim($price)) == 0 || strlen(trim($qt)) == 0) { return ""; } $r = ${'e_march' . $this->counter . '_tva_amount'}; break; /* TVA automatically computed */ /* TVA automatically computed */ case 'VEN_ART_TVA': extract($p_array); $qt = 'e_quant' . $this->counter; $price = 'e_march' . $this->counter . '_price'; $tva = 'e_march' . $this->counter . '_tva_id'; if (!isset(${'e_march' . $this->counter})) { return ""; } // check that something is sold if (${$price} == 0 || ${$qt} == 0 || strlen(trim($price)) == 0 || strlen(trim($qt)) == 0) { return ""; } $oTva = new Acc_Tva($this->db, ${$tva}); if ($oTva->load() == -1) { return ""; } $r = round(${$price}, 2) * $oTva->get_parameter('rate'); $r = round($r, 2); break; case 'VEN_ART_TVAC': extract($p_array); $qt = 'e_quant' . $this->counter; $price = 'e_march' . $this->counter . '_price'; $tva = 'e_march' . $this->counter . '_tva_id'; if (!isset(${'e_march' . $this->counter})) { return ""; } // check that something is sold if (${$price} == 0 || ${$qt} == 0 || strlen(trim($price)) == 0 || strlen(trim($qt)) == 0) { return ""; } if (!isset(${$tva})) { return ''; } $tva = new Acc_Tva($this->db, ${$tva}); if ($tva->load() == -1) { $r = round(${$price}, 2); } else { $r = round(${$price} * $tva->get_parameter('rate') + ${$price}, 2); } break; case 'VEN_ART_QUANT': extract($p_array); $id = 'e_quant' . $this->counter; if (!isset(${$id})) { return ""; } // check that something is sold if (${'e_march' . $this->counter . '_price'} == 0 || ${'e_quant' . $this->counter} == 0 || strlen(trim(${'e_march' . $this->counter . '_price'})) == 0 || strlen(trim(${'e_quant' . $this->counter})) == 0) { return ""; } $r = ${$id}; break; case 'VEN_HTVA': extract($p_array); $id = 'e_march' . $this->counter . '_price'; $quant = 'e_quant' . $this->counter; if (!isset(${$id})) { return ""; } // check that something is sold if (${'e_march' . $this->counter . '_price'} == 0 || ${'e_quant' . $this->counter} == 0 || strlen(trim(${'e_march' . $this->counter . '_price'})) == 0 || strlen(trim(${'e_quant' . $this->counter})) == 0) { return ""; } bcscale(4); $r = bcmul(${$id}, ${$quant}); $r = round($r, 2); break; case 'VEN_TVAC': extract($p_array); $id = 'e_march' . $this->counter . '_tva_amount'; $price = 'e_march' . $this->counter . '_price'; $quant = 'e_quant' . $this->counter; if (!isset(${'e_march' . $this->counter . '_price'}) || !isset(${'e_quant' . $this->counter})) { return ""; } // check that something is sold if (${'e_march' . $this->counter . '_price'} == 0 || ${'e_quant' . $this->counter} == 0) { return ""; } bcscale(4); // if TVA not exist if (!isset(${$id})) { $r = bcmul(${$price}, ${$quant}); } else { $r = bcmul(${$price}, ${$quant}); $r = bcadd($r, ${$id}); } $r = round($r, 2); return $r; break; case 'TOTAL_VEN_HTVA': extract($p_array); bcscale(4); $sum = 0.0; for ($i = 0; $i < $nb_item; $i++) { $sell = 'e_march' . $i . '_price'; $qt = 'e_quant' . $i; if (!isset(${$sell})) { break; } if (strlen(trim(${$sell})) == 0 || strlen(trim(${$qt})) == 0 || ${$qt} == 0 || ${$sell} == 0) { continue; } $tmp1 = bcmul(${$sell}, ${$qt}); $sum = bcadd($sum, $tmp1); } $r = round($sum, 2); break; case 'TOTAL_VEN_TVAC': extract($p_array); $sum = 0.0; bcscale(4); for ($i = 0; $i < $nb_item; $i++) { $tva = 'e_march' . $i . '_tva_amount'; $tva_amount = 0; /* if we do not use vat this var. is not set */ if (isset(${$tva})) { $tva_amount = ${$tva}; } $sell = ${'e_march' . $i . '_price'}; $qt = ${'e_quant' . $i}; $tot = bcmul($sell, $qt); $tot = bcadd($tot, $tva_amount); $sum = bcadd($sum, $tot); } $r = round($sum, 2); break; case 'TOTAL_TVA': extract($p_array); $sum = 0.0; for ($i = 0; $i < $nb_item; $i++) { $tva = 'e_march' . $i . '_tva_amount'; if (!isset(${$tva})) { $tva_amount = 0.0; } else { $tva_amount = ${$tva}; } $sum += $tva_amount; $sum = round($sum, 2); } $r = $sum; break; case 'BON_COMMANDE': if (isset($p_array['bon_comm'])) { return $p_array['bon_comm']; } else { return ""; } break; case 'PJ': if (isset($p_array['e_pj'])) { return $p_array['e_pj']; } else { return ""; } case 'OTHER_INFO': if (isset($p_array['other_info'])) { return $p_array['other_info']; } else { return ""; } break; case 'COMMENT': if (isset($p_array['e_comm'])) { return $p_array['e_comm']; } break; case 'ACOMPTE': if (isset($p_array['acompte'])) { return $p_array['acompte']; } return "0"; break; case 'STOCK_NAME': if (!isset($p_array['repo'])) { return ""; } $ret = $this->db->get_value('select r_name from public.stock_repository where r_id=$1', array($p_array['repo'])); return $ret; case 'STOCK_ADRESS': if (!isset($p_array['repo'])) { return ""; } $ret = $this->db->get_value('select r_adress from public.stock_repository where r_id=$1', array($p_array['repo'])); return $ret; case 'STOCK_COUNTRY': if (!isset($p_array['repo'])) { return ""; } $ret = $this->db->get_value('select r_country from public.stock_repository where r_id=$1', array($p_array['repo'])); return $ret; case 'STOCK_CITY': if (!isset($p_array['repo'])) { return ""; } $ret = $this->db->get_value('select r_city from public.stock_repository where r_id=$1', array($p_array['repo'])); return $ret; case 'STOCK_PHONE': if (!isset($p_array['repo'])) { return ""; } $ret = $this->db->get_value('select r_phone from public.stock_repository where r_id=$1', array($p_array['repo'])); return $ret; case 'TITLE': $title = HtmlInput::default_value_request("ag_title", ""); return $title; } /* * retrieve the value of ATTR for e_march */ if (preg_match('/^ATTR/', $p_tag) == 1) { // Retrieve f_id if (isset($p_array['e_march' . $this->counter])) { $id = $p_array['e_march' . $this->counter]; $r = $this->replace_special_tag($id, $p_tag); } } /* * retrieve the value of ATTR for e_march */ if (preg_match('/^BENEFATTR/', $p_tag) == 1) { $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : ''; // Retrieve f_id $r = $this->replace_special_tag($qcode, $p_tag); } if (preg_match('/^CUSTATTR/', $p_tag) == 1) { if (isset($p_array['qcode_dest']) || isset($p_array['e_client'])) { $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client']; $r = $this->replace_special_tag($qcode, $p_tag); } } return $r; }
echo $act->Display('READ', false, $base, $retour); } else { echo h2info(_("Ce document n'est pas accessible")); return; } } echo '</div>'; } //------------------------------------------------------------------------------- // Delete an action if ($sub_action == 'delete') { // confirmed $cn->start(); $act = new Follow_Up($cn); $act->ag_id = $_REQUEST['ag_id']; $act->get(); if ($g_user->can_write_action($_REQUEST['ag_id']) == true) { $act->remove(); } $sub_action = "list"; $cn->commit(); Follow_Up::show_action_list($cn, $base); if (isset($act->ag_ref)) { echo hb(_('Action ') . $act->ag_ref . _(' effacée')); } return; } //-------------------------------------------------------------------------------- // Show a list of the action if ($sub_action == "list") { // Add a button to export to Csv
static function action_print($cn, $p_array) { global $g_user; $mag_id = $p_array['mag_id']; for ($i = 0; $i < count($mag_id); $i++) { if ($g_user->can_read_action($mag_id[$i]) == false) { continue; } $a = new Follow_Up($cn, $mag_id[$i]); $a->get(); echo '<div class="content">'; echo $a->Display("READ", false, ""); echo '</div>'; echo '<P id="breakhere"> - - </p>'; } }