Fix: Validation of order if a file was attached

This commit is contained in:
Laurent Destailleur 2009-01-15 00:17:57 +00:00
parent 4a794016fb
commit af1cede0ed
3 changed files with 37 additions and 44 deletions

View File

@ -29,6 +29,7 @@ For users:
- Fix: Clicktodial plugin works correctly now - Fix: Clicktodial plugin works correctly now
- Fix: Multiprices features works correctly. - Fix: Multiprices features works correctly.
- Fix: Project module and task creation. - Fix: Project module and task creation.
- Fix: Validation of order if a file was attached.
For translators: For translators:
- Added ca_ES language files - Added ca_ES language files

View File

@ -209,7 +209,7 @@ class Commande extends CommonObject
global $conf,$langs; global $conf,$langs;
$error=0; $error=0;
// Protection // Protection
if ($this->statut == 1) if ($this->statut == 1)
{ {
@ -221,7 +221,7 @@ class Commande extends CommonObject
$this->error='Permission denied'; $this->error='Permission denied';
return -1; return -1;
} }
$this->db->begin(); $this->db->begin();
// Definition du nom de module de numerotation de commande // Definition du nom de module de numerotation de commande
@ -251,34 +251,26 @@ class Commande extends CommonObject
// On efface le repertoire de pdf provisoire // On efface le repertoire de pdf provisoire
if (eregi('^\(PROV', $this->ref)) if (eregi('^\(PROV', $this->ref))
{ {
// On renomme repertoire facture ($this->ref = ancienne ref, $numfa = nouvelle ref)
// afin de ne pas perdre les fichiers attachés
$comref = sanitizeFileName($this->ref); $comref = sanitizeFileName($this->ref);
if ($conf->commande->dir_output) $snum = sanitizeFileName($num);
$dirsource = $conf->commande->dir_output.'/'.$comref;
$dirdest = $conf->commande->dir_output.'/'.$snum;
if (file_exists($dirsource))
{ {
$dir = $conf->commande->dir_output . "/" . $comref ; dol_syslog("Commande::valid() rename dir ".$dirsource." into ".$dirdest);
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
if (file_exists($file))
{
commande_delete_preview($this->db, $this->id, $this->ref);
if (!dol_delete_file($file)) if (@rename($dirsource, $dirdest))
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
$this->db->rollback();
return 0;
}
}
if (file_exists($dir))
{ {
if (!dol_delete_dir($dir)) dol_syslog("Rename ok");
{ // Suppression ancien fichier PDF dans nouveau rep
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); dol_delete_file($conf->commande->dir_output.'/'.$snum.'/'.$comref.'.*');
$this->db->rollback();
return 0;
}
} }
} }
} }
// If stock is incremented on validate order, we must increment it // If stock is incremented on validate order, we must increment it
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
{ {
@ -563,7 +555,7 @@ class Commande extends CommonObject
break; break;
} }
} }
// Mise a jour ref // Mise a jour ref
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; $sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
if ($this->db->query($sql)) if ($this->db->query($sql))
@ -805,10 +797,10 @@ class Commande extends CommonObject
// print "id : ".$value[1].' :qty: '.$value[0].'<br>'; // print "id : ".$value[1].' :qty: '.$value[0].'<br>';
if(! in_array($value[1],$this->products)) if(! in_array($value[1],$this->products))
$this->add_product($value[1], $value[0]); $this->add_product($value[1], $value[0]);
} }
} }
} }
**/ **/
} }
@ -1260,7 +1252,7 @@ class Commande extends CommonObject
if ($result > 0) if ($result > 0)
{ {
$result=$this->update_price(); $result=$this->update_price();
if ($result > 0) if ($result > 0)
{ {
$this->db->commit(); $this->db->commit();
@ -1765,7 +1757,7 @@ class Commande extends CommonObject
if (file_exists($file)) if (file_exists($file))
{ {
commande_delete_preview($this->db, $this->id, $this->ref); commande_delete_preview($this->db, $this->id, $this->ref);
if (!dol_delete_file($file)) if (!dol_delete_file($file))
{ {
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file); $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);

View File

@ -428,9 +428,9 @@ class Facture extends CommonObject
if (! $error) if (! $error)
{ {
} }
// End // End
@ -682,7 +682,7 @@ class Facture extends CommonObject
{ {
global $conf, $langs; global $conf, $langs;
$error=0; $error=0;
// Clean parameters // Clean parameters
if (isset($this->facnumber)) $this->facnumber=trim($this->ref); if (isset($this->facnumber)) $this->facnumber=trim($this->ref);
@ -711,7 +711,7 @@ class Facture extends CommonObject
if (isset($this->note_public)) $this->note_public=trim($this->note_public); if (isset($this->note_public)) $this->note_public=trim($this->note_public);
if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf); if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
if (isset($this->import_key)) $this->import_key=trim($this->import_key); if (isset($this->import_key)) $this->import_key=trim($this->import_key);
// Check parameters // Check parameters
// Put here code to add control on parameters values // Put here code to add control on parameters values
@ -1310,11 +1310,11 @@ class Facture extends CommonObject
$dirdest = $conf->facture->dir_output.'/'.$snumfa; $dirdest = $conf->facture->dir_output.'/'.$snumfa;
if (file_exists($dirsource)) if (file_exists($dirsource))
{ {
dol_syslog("Facture::set_valid() renommage rep ".$dirsource." en ".$dirdest); dol_syslog("Facture::set_valid() rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
dol_syslog("Renommage ok"); dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep // Suppression ancien fichier PDF dans nouveau rep
dol_delete_file($conf->facture->dir_output.'/'.$snumfa.'/'.$facref.'.*'); dol_delete_file($conf->facture->dir_output.'/'.$snumfa.'/'.$facref.'.*');
} }
@ -1393,7 +1393,7 @@ class Facture extends CommonObject
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 0"; $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 0";
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog("Facture::set_draft sql=".$sql, LOG_DEBUG); dol_syslog("Facture::set_draft sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
@ -1412,8 +1412,8 @@ class Facture extends CommonObject
$result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty); $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
} }
} }
} }
return 1; return 1;
} }
else else
@ -1535,7 +1535,7 @@ class Facture extends CommonObject
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];
$total_ttc = $tabprice[2]; $total_ttc = $tabprice[2];
// \TODO A virer // \TODO A virer
// Anciens indicateurs: $price, $remise (a ne plus utiliser) // Anciens indicateurs: $price, $remise (a ne plus utiliser)
$price = $pu; $price = $pu;
@ -1734,7 +1734,7 @@ class Facture extends CommonObject
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
// Efface ligne de facture // Efface ligne de facture
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid = '.$rowid; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid = '.$rowid;
dol_syslog("Facture::Deleteline sql=".$sql); dol_syslog("Facture::Deleteline sql=".$sql);
@ -1746,18 +1746,18 @@ class Facture extends CommonObject
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
$result=$this->update_price(); $result=$this->update_price();
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result = $interface->run_triggers('LINEBILL_DELETE',$this,$user,$langs,$conf); $result = $interface->run_triggers('LINEBILL_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
@ -2531,7 +2531,7 @@ class Facture extends CommonObject
global $conf, $user; global $conf, $user;
$now=gmmktime(); $now=gmmktime();
$this->nbtodo=$this->nbtodolate=0; $this->nbtodo=$this->nbtodolate=0;
$clause = "WHERE"; $clause = "WHERE";