/** * Update database for contract line * @param user User that modify * @param notrigger 0=no, 1=yes (no update trigger) * @return int <0 if KO, >0 if OK */ function update($user, $notrigger=0) { global $conf, $langs; // Clean parameters $this->fk_contrat=trim($this->fk_contrat); $this->fk_product=trim($this->fk_product); $this->statut=trim($this->statut); $this->label=trim($this->label); $this->description=trim($this->description); $this->tva_tx=trim($this->tva_tx); $this->localtax1_tx=trim($this->localtax1_tx); $this->localtax2_tx=trim($this->localtax2_tx); $this->qty=trim($this->qty); $this->remise_percent=trim($this->remise_percent); $this->remise=trim($this->remise); $this->fk_remise_except=trim($this->fk_remise_except); $this->subprice=price2num($this->subprice); $this->price_ht=price2num($this->price_ht); $this->total_ht=trim($this->total_ht); $this->total_tva=trim($this->total_tva); $this->total_localtax1=trim($this->total_localtax1); $this->total_localtax2=trim($this->total_localtax2); $this->total_ttc=trim($this->total_ttc); $this->info_bits=trim($this->info_bits); $this->fk_user_author=trim($this->fk_user_author); $this->fk_user_ouverture=trim($this->fk_user_ouverture); $this->fk_user_cloture=trim($this->fk_user_cloture); $this->commentaire=trim($this->commentaire); // Check parameters // Put here code to add control on parameters values // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET"; $sql.= " fk_contrat='".$this->fk_contrat."',"; $sql.= " fk_product=".($this->fk_product?"'".$this->fk_product."'":'null').","; $sql.= " statut='".$this->statut."',"; $sql.= " label='".$this->db->escape($this->label)."',"; $sql.= " description='".$this->db->escape($this->description)."',"; $sql.= " date_commande=".($this->date_commande!=''?$this->db->idate($this->date_commande):"null").","; $sql.= " date_ouverture_prevue=".($this->date_ouverture_prevue!=''?$this->db->idate($this->date_ouverture_prevue):"null").","; $sql.= " date_ouverture=".($this->date_ouverture!=''?$this->db->idate($this->date_ouverture):"null").","; $sql.= " date_fin_validite=".($this->date_fin_validite!=''?$this->db->idate($this->date_fin_validite):"null").","; $sql.= " date_cloture=".($this->date_cloture!=''?$this->db->idate($this->date_cloture):"null").","; $sql.= " tva_tx='".$this->tva_tx."',"; $sql.= " localtax1_tx='".$this->localtax1_tx."',"; $sql.= " localtax2_tx='".$this->localtax2_tx."',"; $sql.= " qty='".$this->qty."',"; $sql.= " remise_percent='".$this->remise_percent."',"; $sql.= " remise=".($this->remise?"'".$this->remise."'":"null").","; $sql.= " fk_remise_except=".($this->fk_remise_except?"'".$this->fk_remise_except."'":"null").","; $sql.= " subprice='".$this->subprice."',"; $sql.= " price_ht='".$this->price_ht."',"; $sql.= " total_ht='".$this->total_ht."',"; $sql.= " total_tva='".$this->total_tva."',"; $sql.= " total_localtax1='".$this->total_localtax1."',"; $sql.= " total_localtax2='".$this->total_localtax2."',"; $sql.= " total_ttc='".$this->total_ttc."',"; $sql.= " info_bits='".$this->info_bits."',"; $sql.= " fk_user_author=".($this->fk_user_author >= 0?$this->fk_user_author:"NULL").","; $sql.= " fk_user_ouverture=".($this->fk_user_ouverture > 0?$this->fk_user_ouverture:"NULL").","; $sql.= " fk_user_cloture=".($this->fk_user_cloture > 0?$this->fk_user_cloture:"NULL").","; $sql.= " commentaire='".$this->db->escape($this->commentaire)."'"; $sql.= " WHERE rowid=".$this->id; dol_syslog("ContratLigne::update sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $contrat=new Contrat($this->db); $contrat->fetch($this->fk_contrat); $result=$contrat->update_statut($user); } else { $this->error="Error ".$this->db->lasterror(); dol_syslog("ContratLigne::update ".$this->error, LOG_ERR); return -1; } if (! $notrigger) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } return 1; }
/** * Update database for contract line * * @param User $user User that modify * @param int $notrigger 0=no, 1=yes (no update trigger) * @return int <0 if KO, >0 if OK */ function update($user, $notrigger = 0) { global $conf, $langs; $error = 0; // Clean parameters $this->fk_contrat = trim($this->fk_contrat); $this->fk_product = trim($this->fk_product); $this->statut = trim($this->statut); $this->label = trim($this->label); $this->description = trim($this->description); $this->tva_tx = trim($this->tva_tx); $this->localtax1_tx = trim($this->localtax1_tx); $this->localtax2_tx = trim($this->localtax2_tx); $this->qty = trim($this->qty); $this->remise_percent = trim($this->remise_percent); $this->remise = trim($this->remise); $this->fk_remise_except = trim($this->fk_remise_except); $this->subprice = price2num($this->subprice); $this->price_ht = price2num($this->price_ht); $this->total_ht = trim($this->total_ht); $this->total_tva = trim($this->total_tva); $this->total_localtax1 = trim($this->total_localtax1); $this->total_localtax2 = trim($this->total_localtax2); $this->total_ttc = trim($this->total_ttc); $this->info_bits = trim($this->info_bits); $this->fk_user_author = trim($this->fk_user_author); $this->fk_user_ouverture = trim($this->fk_user_ouverture); $this->fk_user_cloture = trim($this->fk_user_cloture); $this->commentaire = trim($this->commentaire); // Check parameters // Put here code to add control on parameters values // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. $tabprice = calcul_price_total($this->qty, $this->price_ht, $this->remise_percent, $this->tva_tx, $this->localtax1_tx, $this->localtax2_tx, 0, 'HT', 0, 1); $this->total_ht = $tabprice[0]; $this->total_tva = $tabprice[1]; $this->total_ttc = $tabprice[2]; $this->total_localtax1 = $tabprice[9]; $this->total_localtax2 = $tabprice[10]; if (empty($this->pa_ht)) { $this->pa_ht = 0; } // si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente if ($this->pa_ht == 0) { if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100); } } $this->db->begin(); // Update request $sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET"; $sql .= " fk_contrat='" . $this->fk_contrat . "',"; $sql .= " fk_product=" . ($this->fk_product ? "'" . $this->fk_product . "'" : 'null') . ","; $sql .= " statut='" . $this->statut . "',"; $sql .= " label='" . $this->db->escape($this->label) . "',"; $sql .= " description='" . $this->db->escape($this->description) . "',"; $sql .= " date_commande=" . ($this->date_commande != '' ? "'" . $this->db->idate($this->date_commande) . "'" : "null") . ","; $sql .= " date_ouverture_prevue=" . ($this->date_ouverture_prevue != '' ? "'" . $this->db->idate($this->date_ouverture_prevue) . "'" : "null") . ","; $sql .= " date_ouverture=" . ($this->date_ouverture != '' ? "'" . $this->db->idate($this->date_ouverture) . "'" : "null") . ","; $sql .= " date_fin_validite=" . ($this->date_fin_validite != '' ? "'" . $this->db->idate($this->date_fin_validite) . "'" : "null") . ","; $sql .= " date_cloture=" . ($this->date_cloture != '' ? "'" . $this->db->idate($this->date_cloture) . "'" : "null") . ","; $sql .= " tva_tx='" . $this->tva_tx . "',"; $sql .= " localtax1_tx='" . $this->localtax1_tx . "',"; $sql .= " localtax2_tx='" . $this->localtax2_tx . "',"; $sql .= " qty='" . $this->qty . "',"; $sql .= " remise_percent='" . $this->remise_percent . "',"; $sql .= " remise=" . ($this->remise ? "'" . $this->remise . "'" : "null") . ","; $sql .= " fk_remise_except=" . ($this->fk_remise_except ? "'" . $this->fk_remise_except . "'" : "null") . ","; $sql .= " subprice='" . $this->subprice . "',"; $sql .= " price_ht='" . $this->price_ht . "',"; $sql .= " total_ht='" . $this->total_ht . "',"; $sql .= " total_tva='" . $this->total_tva . "',"; $sql .= " total_localtax1='" . $this->total_localtax1 . "',"; $sql .= " total_localtax2='" . $this->total_localtax2 . "',"; $sql .= " total_ttc='" . $this->total_ttc . "',"; $sql .= " fk_product_fournisseur_price=" . (!empty($this->fk_fournprice) ? $this->fk_fournprice : "NULL") . ","; $sql .= " buy_price_ht='" . price2num($this->pa_ht) . "',"; $sql .= " info_bits='" . $this->info_bits . "',"; $sql .= " fk_user_author=" . ($this->fk_user_author >= 0 ? $this->fk_user_author : "NULL") . ","; $sql .= " fk_user_ouverture=" . ($this->fk_user_ouverture > 0 ? $this->fk_user_ouverture : "NULL") . ","; $sql .= " fk_user_cloture=" . ($this->fk_user_cloture > 0 ? $this->fk_user_cloture : "NULL") . ","; $sql .= " commentaire='" . $this->db->escape($this->commentaire) . "'"; $sql .= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::update", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $contrat = new Contrat($this->db); $contrat->fetch($this->fk_contrat); $result = $contrat->update_statut($user); } else { $this->error = "Error " . $this->db->lasterror(); $this->db->rollback(); return -1; } if (!$notrigger) { // Call trigger $result = $this->call_trigger('LINECONTRACT_UPDATE', $user); if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers } $this->db->commit(); return 1; }
/** * testContratValid * * @param Contrat $localobject Contract * @return int * * @depends testContratFetch * The depends says test is run only if previous is ok */ public function testContratValid($localobject) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $result=$localobject->update_statut($user); print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); return $localobject; }
/** * Update database for contract line * * @param User $user User that modify * @param int $notrigger 0=no, 1=yes (no update trigger) * @return int <0 if KO, >0 if OK */ function update($user, $notrigger = 0) { global $conf, $langs; $error = 0; // Clean parameters $this->fk_contrat = trim($this->fk_contrat); $this->fk_product = trim($this->fk_product); $this->statut = trim($this->statut); $this->label = trim($this->label); $this->description = trim($this->description); $this->tva_tx = trim($this->tva_tx); $this->localtax1_tx = trim($this->localtax1_tx); $this->localtax2_tx = trim($this->localtax2_tx); $this->qty = trim($this->qty); $this->remise_percent = trim($this->remise_percent); $this->remise = trim($this->remise); $this->fk_remise_except = trim($this->fk_remise_except); $this->subprice = price2num($this->subprice); $this->price_ht = price2num($this->price_ht); $this->total_ht = trim($this->total_ht); $this->total_tva = trim($this->total_tva); $this->total_localtax1 = trim($this->total_localtax1); $this->total_localtax2 = trim($this->total_localtax2); $this->total_ttc = trim($this->total_ttc); $this->info_bits = trim($this->info_bits); $this->fk_user_author = trim($this->fk_user_author); $this->fk_user_ouverture = trim($this->fk_user_ouverture); $this->fk_user_cloture = trim($this->fk_user_cloture); $this->commentaire = trim($this->commentaire); // Check parameters // Put here code to add control on parameters values // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. $tabprice = calcul_price_total($this->qty, $this->price_ht, $this->remise_percent, $this->tva_tx, $this->localtax1_tx, $this->localtax2_tx, 0, 'HT', 0); $this->total_ht = $tabprice[0]; $this->total_tva = $tabprice[1]; $this->total_ttc = $tabprice[2]; $this->total_localtax1 = $tabprice[9]; $this->total_localtax2 = $tabprice[10]; // Update request $sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET"; $sql .= " fk_contrat='" . $this->fk_contrat . "',"; $sql .= " fk_product=" . ($this->fk_product ? "'" . $this->fk_product . "'" : 'null') . ","; $sql .= " statut='" . $this->statut . "',"; $sql .= " label='" . $this->db->escape($this->label) . "',"; $sql .= " description='" . $this->db->escape($this->description) . "',"; $sql .= " date_commande=" . ($this->date_commande != '' ? "'" . $this->db->idate($this->date_commande) . "'" : "null") . ","; $sql .= " date_ouverture_prevue=" . ($this->date_ouverture_prevue != '' ? "'" . $this->db->idate($this->date_ouverture_prevue) . "'" : "null") . ","; $sql .= " date_ouverture=" . ($this->date_ouverture != '' ? "'" . $this->db->idate($this->date_ouverture) . "'" : "null") . ","; $sql .= " date_fin_validite=" . ($this->date_fin_validite != '' ? "'" . $this->db->idate($this->date_fin_validite) . "'" : "null") . ","; $sql .= " date_cloture=" . ($this->date_cloture != '' ? "'" . $this->db->idate($this->date_cloture) . "'" : "null") . ","; $sql .= " tva_tx='" . $this->tva_tx . "',"; $sql .= " localtax1_tx='" . $this->localtax1_tx . "',"; $sql .= " localtax2_tx='" . $this->localtax2_tx . "',"; $sql .= " qty='" . $this->qty . "',"; $sql .= " remise_percent='" . $this->remise_percent . "',"; $sql .= " remise=" . ($this->remise ? "'" . $this->remise . "'" : "null") . ","; $sql .= " fk_remise_except=" . ($this->fk_remise_except ? "'" . $this->fk_remise_except . "'" : "null") . ","; $sql .= " subprice='" . $this->subprice . "',"; $sql .= " price_ht='" . $this->price_ht . "',"; $sql .= " total_ht='" . $this->total_ht . "',"; $sql .= " total_tva='" . $this->total_tva . "',"; $sql .= " total_localtax1='" . $this->total_localtax1 . "',"; $sql .= " total_localtax2='" . $this->total_localtax2 . "',"; $sql .= " total_ttc='" . $this->total_ttc . "',"; $sql .= " info_bits='" . $this->info_bits . "',"; $sql .= " fk_user_author=" . ($this->fk_user_author >= 0 ? $this->fk_user_author : "NULL") . ","; $sql .= " fk_user_ouverture=" . ($this->fk_user_ouverture > 0 ? $this->fk_user_ouverture : "NULL") . ","; $sql .= " fk_user_cloture=" . ($this->fk_user_cloture > 0 ? $this->fk_user_cloture : "NULL") . ","; $sql .= " commentaire='" . $this->db->escape($this->commentaire) . "'"; $sql .= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $contrat = new Contrat($this->db); $contrat->fetch($this->fk_contrat); $result = $contrat->update_statut($user); } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::update " . $this->error, LOG_ERR); return -1; } if (!$notrigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"; $interface = new Interfaces($this->db); $result = $interface->run_triggers('MYOBJECT_MODIFY', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } return 1; }
/** * Update database for contract line * * @param User $user User that modify * @param int $notrigger 0=no, 1=yes (no update trigger) * @return int <0 if KO, >0 if OK */ function update($user, $notrigger = 0) { global $conf, $langs, $mysoc; $error = 0; // Clean parameters $this->fk_contrat = trim($this->fk_contrat); $this->fk_product = trim($this->fk_product); $this->statut = (int) $this->statut; $this->label = trim($this->label); $this->description = trim($this->description); $this->tva_tx = trim($this->tva_tx); $this->localtax1_tx = trim($this->localtax1_tx); $this->localtax2_tx = trim($this->localtax2_tx); $this->qty = trim($this->qty); $this->remise_percent = trim($this->remise_percent); $this->remise = trim($this->remise); $this->fk_remise_except = trim($this->fk_remise_except); $this->subprice = price2num($this->subprice); $this->price_ht = price2num($this->price_ht); $this->total_ht = trim($this->total_ht); $this->total_tva = trim($this->total_tva); $this->total_localtax1 = trim($this->total_localtax1); $this->total_localtax2 = trim($this->total_localtax2); $this->total_ttc = trim($this->total_ttc); $this->info_bits = trim($this->info_bits); $this->fk_user_author = trim($this->fk_user_author); $this->fk_user_ouverture = trim($this->fk_user_ouverture); $this->fk_user_cloture = trim($this->fk_user_cloture); $this->commentaire = trim($this->commentaire); //if (empty($this->subprice)) $this->subprice = 0; if (empty($this->price_ht)) { $this->price_ht = 0; } if (empty($this->total_ht)) { $this->total_ht = 0; } if (empty($this->total_tva)) { $this->total_tva = 0; } if (empty($this->total_ttc)) { $this->total_ttc = 0; } // Check parameters // Put here code to add control on parameters values // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. $localtaxes_type = getLocalTaxesFromRate($this->txtva, 0, $this->societe, $mysoc); $tabprice = calcul_price_total($this->qty, $this->price_ht, $this->remise_percent, $this->tva_tx, $this->localtax1_tx, $this->localtax2_tx, 0, 'HT', 0, 1, $mysoc, $localtaxes_type); $this->total_ht = $tabprice[0]; $this->total_tva = $tabprice[1]; $this->total_ttc = $tabprice[2]; $this->total_localtax1 = $tabprice[9]; $this->total_localtax2 = $tabprice[10]; if (empty($this->pa_ht)) { $this->pa_ht = 0; } // if buy price not defined, define buyprice as configured in margin admin if ($this->pa_ht == 0) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { return $result; } else { $this->pa_ht = $result; } } $this->db->begin(); // Update request $sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET"; $sql .= " fk_contrat='" . $this->fk_contrat . "',"; $sql .= " fk_product=" . ($this->fk_product ? "'" . $this->fk_product . "'" : 'null') . ","; $sql .= " statut='" . $this->statut . "',"; $sql .= " label='" . $this->db->escape($this->label) . "',"; $sql .= " description='" . $this->db->escape($this->description) . "',"; $sql .= " date_commande=" . ($this->date_commande != '' ? "'" . $this->db->idate($this->date_commande) . "'" : "null") . ","; $sql .= " date_ouverture_prevue=" . ($this->date_ouverture_prevue != '' ? "'" . $this->db->idate($this->date_ouverture_prevue) . "'" : "null") . ","; $sql .= " date_ouverture=" . ($this->date_ouverture != '' ? "'" . $this->db->idate($this->date_ouverture) . "'" : "null") . ","; $sql .= " date_fin_validite=" . ($this->date_fin_validite != '' ? "'" . $this->db->idate($this->date_fin_validite) . "'" : "null") . ","; $sql .= " date_cloture=" . ($this->date_cloture != '' ? "'" . $this->db->idate($this->date_cloture) . "'" : "null") . ","; $sql .= " tva_tx='" . $this->tva_tx . "',"; $sql .= " localtax1_tx='" . $this->localtax1_tx . "',"; $sql .= " localtax2_tx='" . $this->localtax2_tx . "',"; $sql .= " qty='" . $this->qty . "',"; $sql .= " remise_percent='" . $this->remise_percent . "',"; $sql .= " remise=" . ($this->remise ? "'" . $this->remise . "'" : "null") . ","; $sql .= " fk_remise_except=" . ($this->fk_remise_except ? "'" . $this->fk_remise_except . "'" : "null") . ","; $sql .= " subprice=" . ($this->subprice != '' ? $this->subprice : "null") . ","; $sql .= " price_ht=" . ($this->price_ht != '' ? $this->price_ht : "null") . ","; $sql .= " total_ht='" . $this->total_ht . "',"; $sql .= " total_tva='" . $this->total_tva . "',"; $sql .= " total_localtax1='" . $this->total_localtax1 . "',"; $sql .= " total_localtax2='" . $this->total_localtax2 . "',"; $sql .= " total_ttc='" . $this->total_ttc . "',"; $sql .= " fk_product_fournisseur_price=" . (!empty($this->fk_fournprice) ? $this->fk_fournprice : "NULL") . ","; $sql .= " buy_price_ht='" . price2num($this->pa_ht) . "',"; $sql .= " info_bits='" . $this->info_bits . "',"; $sql .= " fk_user_author=" . ($this->fk_user_author >= 0 ? $this->fk_user_author : "NULL") . ","; $sql .= " fk_user_ouverture=" . ($this->fk_user_ouverture > 0 ? $this->fk_user_ouverture : "NULL") . ","; $sql .= " fk_user_cloture=" . ($this->fk_user_cloture > 0 ? $this->fk_user_cloture : "NULL") . ","; $sql .= " commentaire='" . $this->db->escape($this->commentaire) . "'"; $sql .= ", fk_unit=" . (!$this->fk_unit ? 'NULL' : $this->fk_unit); $sql .= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::update", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $contrat = new Contrat($this->db); $contrat->fetch($this->fk_contrat); $result = $contrat->update_statut($user); } else { $this->error = "Error " . $this->db->lasterror(); $error++; //return -1; } if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) { $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } if (empty($error)) { if (!$notrigger) { // Call trigger $result = $this->call_trigger('LINECONTRACT_UPDATE', $user); if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers } } if (empty($error)) { $this->db->commit(); return 1; } else { $this->db->rollback(); $this->errors[] = $this->error; return -1; } }