예제 #1
0
    /* Second step : we save the name and category
     * and propose the items we add the item */
    if ($correct == 2 || isset($_POST['step2'])) {
        try {
            $cn->start();
            /* Save forecast */
            $a = new Forecast($cn);
            $a->set_parameter('name', $_POST['an_name']);
            $a->set_parameter('start_date', $_POST['start_date']);
            $a->set_parameter('end_date', $_POST['end_date']);
            $a->save();
            $id = $a->get_parameter("id");
            /* save cat */
            for ($i = 0; $i < MAX_CAT; $i++) {
                if (strlen(trim($_POST['fr_cat' . $i])) != 0) {
                    $c = new Forecast_Cat($cn);
                    $c->set_parameter('order', $_POST['fr_order' . $i]);
                    $c->set_parameter('desc', $_POST['fr_cat' . $i]);
                    $c->set_parameter('forecast', $id);
                    $c->save();
                }
            }
            $cn->commit();
        } catch (Exception $e) {
            alert($e->getMessage());
            $correct = 1;
            unset($_POST['step2']);
            $cn->rollback();
        }
    }
}
예제 #2
0
 /**
  *@brief display a form for modifying or add a forecast
  *@return HTML code
  */
 public function form_item()
 {
     $forecast = new Forecast($this->cn, $this->f_id);
     $forecast->load();
     $str_name = $forecast->get_parameter('name');
     $str_start = $forecast->get_parameter('start_date');
     $str_end = $forecast->get_parameter('end_date');
     $r = "";
     $str_action = _("Elements");
     $cat = new Forecast_Cat($this->cn);
     $array = $cat->make_array($this->f_id);
     $periode = new Periode($this->cn);
     $aPeriode = $this->cn->make_array("select p_id,to_char(p_start,'MM.YYYY') as label from parm_periode\n                                  where p_start >= (select p_start from parm_periode where p_id={$str_start})\n                                   and p_end <= (select p_end from parm_periode where p_id={$str_end})\n\t\t\t\t   order by p_start");
     $aPeriode[] = array('value' => 0, 'label' => 'Mensuel');
     $value = $this->cn->get_array("select fi_id,fi_text,fi_account,fi_card,fc_id,fi_amount,fi_debit,fi_pid " . " from forecast_item " . " \twhere fc_id in (select fc_id from forecast_cat where f_id = \$1)", array($this->f_id));
     $max = count($value) < MAX_FORECAST_ITEM ? MAX_FORECAST_ITEM : count($value);
     $r .= HtmlInput::hidden('nbrow', $max);
     for ($i = 0; $i < $max; $i++) {
         if (isset($value[$i]['fi_id'])) {
             $r .= HtmlInput::hidden('fi_id' . $i, $value[$i]['fi_id']);
         }
         /* category*/
         $category = new ISelect();
         $category->name = 'an_cat' . $i;
         $category->value = $array;
         $category->selected = isset($value[$i]["fc_id"]) ? $value[$i]["fc_id"] : -1;
         $aCat[$i]['cat'] = $category->input();
         /* amount 	 */
         $amount = new INum('an_cat_amount' . $i);
         $amount->value = isset($value[$i]["fi_amount"]) ? $value[$i]["fi_amount"] : 0;
         $aCat[$i]['amount'] = $amount->input();
         /* Accounting*/
         $account = new IPoste('an_cat_acc' . $i);
         $account->set_attribute('ipopup', 'ipop_account');
         //            $account->set_attribute('label','an_label'.$i);
         $account->set_attribute('account', 'an_cat_acc' . $i);
         $account->set_attribute('bracket', 1);
         $account->set_attribute('no_overwrite', 1);
         $account->set_attribute('noquery', 1);
         $account->css_size = "85%";
         $account->value = isset($value[$i]["fi_account"]) ? $value[$i]["fi_account"] : "";
         $aCat[$i]['account'] = $account->input();
         /*Quick Code */
         $qc = new ICard('an_qc' . $i);
         // If double click call the javascript fill_ipopcard
         $qc->set_dblclick("fill_ipopcard(this);");
         // This attribute is mandatory, it is the name of the IPopup
         $qc->set_attribute('ipopup', 'ipopcard');
         // name of the field to update with the name of the card
         $qc->set_attribute('label', 'an_label' . $i);
         // Type of card : all
         $qc->set_attribute('typecard', 'all');
         $qc->set_attribute('jrn', 0);
         $qc->extra = 'all';
         // when value selected in the autcomplete
         $qc->set_function('fill_data');
         if (isset($value[$i]["fi_card"])) {
             $f = new Fiche($this->cn, $value[$i]["fi_card"]);
             $qc->value = $f->strAttribut(ATTR_DEF_QUICKCODE);
         }
         $aCat[$i]['qc'] = $qc->search() . $qc->input();
         /* Label */
         $label = new IText('an_label' . $i);
         $label->value = isset($value[$i]["fi_text"]) ? $value[$i]["fi_text"] : "";
         $aCat[$i]['name'] = $label->input();
         //Deb or Cred
         $deb = new ISelect('an_deb' . $i);
         $deb->selected = isset($value[$i]["fi_debit"]) ? $value[$i]["fi_debit"] : -1;
         $deb->value = array(array('value' => 'D', 'label' => _('Débit')), array('value' => 'C', 'label' => _('Crédit')));
         $aCat[$i]['deb'] = $deb->input();
         //Periode
         $isPeriode = new ISelect('month' . $i);
         $isPeriode->value = $aPeriode;
         $isPeriode->selected = isset($value[$i]["fi_pid"]) ? $value[$i]["fi_pid"] : 0;
         $aCat[$i]['per'] = $isPeriode->input();
     }
     $add_row = new IButton('add_row');
     $add_row->label = _('Ajouter une ligne');
     $add_row->javascript = 'for_add_row(\'fortable\')';
     $f_add_row = $add_row->input();
     ob_start();
     require_once NOALYSS_INCLUDE . '/template/forecast-detail.php';
     $r .= ob_get_contents();
     ob_end_clean();
     return $r;
 }