function doActions($parameters, &$object, &$action, $hookmanager)
 {
     if (GETPOST('addcontratline')) {
         $fk_line_contrat_origin = GETPOST('fk_line_contrat_origin', 'int');
         if ($fk_line_contrat_origin > 0) {
             global $db;
             dol_include_once('/contrat/class/contrat.class.php');
             $lineContrat = new ContratLigne($db);
             $res = $lineContrat->fetch($fk_line_contrat_origin);
             if ($res > 0) {
                 $linePropal = new PropaleLigne($db);
                 $array_options = array();
                 require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
                 $extrafields = new ExtraFields($db);
                 $TExtra = $extrafields->fetch_name_optionals_label($linePropal->table_element);
                 // Récupération des extrafields de la ligne contrat vers la ligne propal
                 $lineContrat->fetch_optionals();
                 foreach ($lineContrat->array_options as $key => $val) {
                     $subkey = substr($key, 8);
                     if (isset($TExtra[$subkey])) {
                         $array_options[$key] = $val;
                     }
                 }
                 if (isset($TExtra['fk_contratdet_origin'])) {
                     $array_options['options_fk_contratdet_origin'] = $lineContrat->id;
                 }
                 $object->addline($lineContrat->description, $lineContrat->subprice, $lineContrat->qty, $lineContrat->tva_tx, $lineContrat->localtax1_tx, $lineContrat->localtax2_tx, $lineContrat->fk_product, $lineContrat->remise_percent, 'HT', 0.0, $lineContrat->info_bits, 1, -1, 0, 0, 0, $lineContrat->pa_ht, '', $lineContrat->date_ouverture_prevue, $lineContrat->date_fin_validite, $array_options, $lineContrat->fk_unit);
             }
         }
     }
 }
Ejemplo n.º 2
0
         }
         if ($conf->global->PRODUCT_USE_UNITS) {
             $colspan++;
         }
         // Ligne dates prevues
         print "<tr " . $bc[$var] . ">";
         print '<td colspan="' . $colspan . '">';
         print $langs->trans("DateStartPlanned") . ' ';
         $form->select_date($db->jdate($objp->date_debut), "date_start_update", $usehm, $usehm, $db->jdate($objp->date_debut) > 0 ? 0 : 1, "update");
         print ' &nbsp;&nbsp;' . $langs->trans("DateEndPlanned") . ' ';
         $form->select_date($db->jdate($objp->date_fin), "date_end_update", $usehm, $usehm, $db->jdate($objp->date_fin) > 0 ? 0 : 1, "update");
         print '</td>';
         if (is_array($extralabelslines) && count($extralabelslines) > 0) {
             print '<tr ' . $bc[$var] . '>';
             $line = new ContratLigne($db);
             $line->fetch_optionals($objp->rowid, $extralabelslines);
             print $line->showOptionals($extrafieldsline, 'edit', array('style' => $bc[$var], 'colspan' => $colspan));
             print '</tr>';
         }
         print '</tr>';
     }
     $db->free($result);
 } else {
     dol_print_error($db);
 }
 if ($object->statut > 0) {
     print '<tr ' . $bc[$var] . '>';
     print '<td colspan="' . ($conf->margin->enabled ? 7 : 6) . '"><hr></td>';
     print "</tr>\n";
 }
 print "</table>";
Ejemplo n.º 3
0
 /**
  *  Load lines array into this->lines
  *
  *  @return ContratLigne[]   Return array of contract lines
  */
 function fetch_lines()
 {
     $this->nbofserviceswait = 0;
     $this->nbofservicesopened = 0;
     $this->nbofservicesexpired = 0;
     $this->nbofservicesclosed = 0;
     $total_ttc = 0;
     $total_vat = 0;
     $total_ht = 0;
     $now = dol_now();
     require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
     $extrafieldsline = new ExtraFields($this->db);
     $line = new ContratLigne($this->db);
     $extralabelsline = $extrafieldsline->fetch_name_optionals_label($line->table_element, true);
     $this->lines = array();
     // Selectionne les lignes contrats liees a un produit
     $sql = "SELECT p.label as product_label, p.description as product_desc, p.ref as product_ref,";
     $sql .= " d.rowid, d.fk_contrat, d.statut, d.description, d.price_ht, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.remise_percent, d.subprice, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht,";
     $sql .= " d.total_ht,";
     $sql .= " d.total_tva,";
     $sql .= " d.total_localtax1,";
     $sql .= " d.total_localtax2,";
     $sql .= " d.total_ttc,";
     $sql .= " d.info_bits, d.fk_product,";
     $sql .= " d.date_ouverture_prevue, d.date_ouverture,";
     $sql .= " d.date_fin_validite, d.date_cloture,";
     $sql .= " d.fk_user_author,";
     $sql .= " d.fk_user_ouverture,";
     $sql .= " d.fk_user_cloture,";
     $sql .= " d.fk_unit";
     $sql .= " FROM " . MAIN_DB_PREFIX . "contratdet as d, " . MAIN_DB_PREFIX . "product as p";
     $sql .= " WHERE d.fk_contrat = " . $this->id . " AND d.fk_product = p.rowid";
     $sql .= " ORDER by d.rowid ASC";
     dol_syslog(get_class($this) . "::fetch_lines", LOG_DEBUG);
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         $i = 0;
         while ($i < $num) {
             $objp = $this->db->fetch_object($result);
             $line = new ContratLigne($this->db);
             $line->id = $objp->rowid;
             $line->ref = $objp->rowid;
             $line->fk_contrat = $objp->fk_contrat;
             $line->desc = $objp->description;
             // Description ligne
             $line->qty = $objp->qty;
             $line->tva_tx = $objp->tva_tx;
             $line->localtax1_tx = $objp->localtax1_tx;
             $line->localtax2_tx = $objp->localtax2_tx;
             $line->subprice = $objp->subprice;
             $line->statut = $objp->statut;
             $line->remise_percent = $objp->remise_percent;
             $line->price_ht = $objp->price_ht;
             $line->price = $objp->price_ht;
             // For backward compatibility
             $line->total_ht = $objp->total_ht;
             $line->total_tva = $objp->total_tva;
             $line->total_localtax1 = $objp->total_localtax1;
             $line->total_localtax2 = $objp->total_localtax2;
             $line->total_ttc = $objp->total_ttc;
             $line->fk_product = $objp->fk_product;
             $line->info_bits = $objp->info_bits;
             $line->fk_fournprice = $objp->fk_fournprice;
             $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
             $line->pa_ht = $marginInfos[0];
             $line->fk_user_author = $objp->fk_user_author;
             $line->fk_user_ouverture = $objp->fk_user_ouverture;
             $line->fk_user_cloture = $objp->fk_user_cloture;
             $line->fk_unit = $objp->fk_unit;
             $line->ref = $objp->product_ref;
             // deprecated
             $line->label = $objp->product_label;
             // deprecated
             $line->libelle = $objp->product_label;
             // deprecated
             $line->product_ref = $objp->product_ref;
             // Ref product
             $line->product_desc = $objp->product_desc;
             // Description product
             $line->product_label = $objp->product_label;
             // Label product
             $line->description = $objp->description;
             $line->date_ouverture_prevue = $this->db->jdate($objp->date_ouverture_prevue);
             $line->date_ouverture = $this->db->jdate($objp->date_ouverture);
             $line->date_fin_validite = $this->db->jdate($objp->date_fin_validite);
             $line->date_cloture = $this->db->jdate($objp->date_cloture);
             // For backward compatibility
             $line->date_debut_prevue = $this->db->jdate($objp->date_ouverture_prevue);
             $line->date_debut_reel = $this->db->jdate($objp->date_ouverture);
             $line->date_fin_prevue = $this->db->jdate($objp->date_fin_validite);
             $line->date_fin_reel = $this->db->jdate($objp->date_cloture);
             // Retreive all extrafield for propal
             // fetch optionals attributes and labels
             $line->fetch_optionals($line->id, $extralabelsline);
             $this->lines[] = $line;
             //dol_syslog("1 ".$line->desc);
             //dol_syslog("2 ".$line->product_desc);
             if ($line->statut == 0) {
                 $this->nbofserviceswait++;
             }
             if ($line->statut == 4 && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) {
                 $this->nbofservicesopened++;
             }
             if ($line->statut == 4 && (!empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) {
                 $this->nbofservicesexpired++;
             }
             if ($line->statut == 5) {
                 $this->nbofservicesclosed++;
             }
             $total_ttc += $objp->total_ttc;
             // TODO Not saved into database
             $total_vat += $objp->total_tva;
             $total_ht += $objp->total_ht;
             $i++;
         }
         $this->db->free($result);
     } else {
         dol_syslog(get_class($this) . "::Fetch Erreur lecture des lignes de contrats liees aux produits");
         return -3;
     }
     // Selectionne les lignes contrat liees a aucun produit
     $sql = "SELECT d.rowid, d.fk_contrat, d.statut, d.qty, d.description, d.price_ht, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.rowid, d.remise_percent, d.subprice,";
     $sql .= " d.total_ht,";
     $sql .= " d.total_tva,";
     $sql .= " d.total_localtax1,";
     $sql .= " d.total_localtax2,";
     $sql .= " d.total_ttc,";
     $sql .= " d.info_bits, d.fk_product,";
     $sql .= " d.date_ouverture_prevue, d.date_ouverture,";
     $sql .= " d.date_fin_validite, d.date_cloture,";
     $sql .= " d.fk_user_author,";
     $sql .= " d.fk_user_ouverture,";
     $sql .= " d.fk_user_cloture,";
     $sql .= " d.fk_unit";
     $sql .= " FROM " . MAIN_DB_PREFIX . "contratdet as d";
     $sql .= " WHERE d.fk_contrat = " . $this->id;
     $sql .= " AND (d.fk_product IS NULL OR d.fk_product = 0)";
     // fk_product = 0 gardee pour compatibilitee
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         $i = 0;
         while ($i < $num) {
             $objp = $this->db->fetch_object($result);
             $line = new ContratLigne($this->db);
             $line->id = $objp->rowid;
             $line->fk_contrat = $objp->fk_contrat;
             $line->libelle = $objp->description;
             $line->desc = $objp->description;
             $line->qty = $objp->qty;
             $line->statut = $objp->statut;
             $line->ref = '';
             $line->tva_tx = $objp->tva_tx;
             $line->localtax1_tx = $objp->localtax1_tx;
             $line->localtax2_tx = $objp->localtax2_tx;
             $line->subprice = $objp->subprice;
             $line->remise_percent = $objp->remise_percent;
             $line->price_ht = $objp->price_ht;
             $line->price = isset($objp->price) ? $objp->price : null;
             // For backward compatibility
             $line->total_ht = $objp->total_ht;
             $line->total_tva = $objp->total_tva;
             $line->total_localtax1 = $objp->total_localtax1;
             $line->total_localtax2 = $objp->total_localtax2;
             $line->total_ttc = $objp->total_ttc;
             $line->fk_product = 0;
             $line->info_bits = $objp->info_bits;
             $line->fk_user_author = $objp->fk_user_author;
             $line->fk_user_ouverture = $objp->fk_user_ouverture;
             $line->fk_user_cloture = $objp->fk_user_cloture;
             $line->description = $objp->description;
             $line->date_ouverture_prevue = $this->db->jdate($objp->date_ouverture_prevue);
             $line->date_ouverture = $this->db->jdate($objp->date_ouverture);
             $line->date_fin_validite = $this->db->jdate($objp->date_fin_validite);
             $line->date_cloture = $this->db->jdate($objp->date_cloture);
             // For backward compatibility
             $line->date_debut_prevue = $this->db->jdate($objp->date_ouverture_prevue);
             $line->date_debut_reel = $this->db->jdate($objp->date_ouverture);
             $line->date_fin_prevue = $this->db->jdate($objp->date_fin_validite);
             $line->date_fin_reel = $this->db->jdate($objp->date_cloture);
             $line->fk_unit = $objp->fk_unit;
             if ($line->statut == 0) {
                 $this->nbofserviceswait++;
             }
             if ($line->statut == 4 && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) {
                 $this->nbofservicesopened++;
             }
             if ($line->statut == 4 && (!empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) {
                 $this->nbofservicesexpired++;
             }
             if ($line->statut == 5) {
                 $this->nbofservicesclosed++;
             }
             // Retreive all extrafield for propal
             // fetch optionals attributes and labels
             $line->fetch_optionals($line->id, $extralabelsline);
             $this->lines[] = $line;
             $total_ttc += $objp->total_ttc;
             $total_vat += $objp->total_tva;
             $total_ht += $objp->total_ht;
             $i++;
         }
         $this->db->free($result);
     } else {
         dol_syslog(get_class($this) . "::Fetch Erreur lecture des lignes de contrat non liees aux produits");
         $this->error = $this->db->error();
         return -2;
     }
     $this->nbofservices = count($this->lines);
     $this->total_ttc = price2num($total_ttc);
     // TODO For the moment value is false as value is not stored in database for line linked to products
     $this->total_vat = price2num($total_vat);
     // TODO For the moment value is false as value is not stored in database for line linked to products
     $this->total_ht = price2num($total_ht);
     // TODO For the moment value is false as value is not stored in database for line linked to products
     return $this->lines;
 }