Uniformize code
This commit is contained in:
parent
d3e8f6f3f9
commit
9a2a1f6c06
@ -332,7 +332,6 @@ if ($_GET['action'] == 'modif' && $user->rights->facture->modifier)
|
||||
$sql.= ' WHERE pf.fk_facture = '.$fac->id;
|
||||
|
||||
$result = $db->query($sql);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$i = 0;
|
||||
@ -340,11 +339,15 @@ if ($_GET['action'] == 'modif' && $user->rights->facture->modifier)
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($result);
|
||||
$totalpaye += $objp->amount;
|
||||
$i++;
|
||||
$objp = $db->fetch_object($result);
|
||||
$totalpaye += $objp->amount;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db,'');
|
||||
}
|
||||
|
||||
$resteapayer = $fac->total_ttc - $totalpaye;
|
||||
|
||||
|
||||
@ -373,7 +373,7 @@ if ($_GET['action'] == 'addline')
|
||||
$outputlangs = new Translate("",$conf);
|
||||
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
|
||||
}
|
||||
//supplier_invoice_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
|
||||
//supplier_invoice_pdf_create($db, $fac->id, $fac->modelpdf, $outputlangs);
|
||||
|
||||
unset($_POST['qty']);
|
||||
unset($_POST['type']);
|
||||
@ -400,6 +400,53 @@ if ($_POST['action'] == 'classin')
|
||||
}
|
||||
|
||||
|
||||
// Repasse la facture en mode brouillon
|
||||
if ($_GET['action'] == 'edit' && $user->rights->fournisseur->facture->creer)
|
||||
{
|
||||
$fac = new FactureFournisseur($db);
|
||||
$fac->fetch($_GET['facid']);
|
||||
|
||||
// On verifie si la facture a des paiements
|
||||
$sql = 'SELECT pf.amount';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf';
|
||||
$sql.= ' WHERE pf.fk_facturefourn = '.$fac->id;
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$i = 0;
|
||||
$num = $db->num_rows($result);
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($result);
|
||||
$totalpaye += $objp->amount;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$resteapayer = $fac->total_ttc - $totalpaye;
|
||||
|
||||
// On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
|
||||
//$ventilExportCompta = $fac->getVentilExportCompta();
|
||||
|
||||
// On verifie si aucun paiement n'a ete effectue
|
||||
if ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0)
|
||||
{
|
||||
$fac->set_draft($user);
|
||||
|
||||
$outputlangs = $langs;
|
||||
if (! empty($_REQUEST['lang_id']))
|
||||
{
|
||||
$outputlangs = new Translate("",$conf);
|
||||
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
|
||||
}
|
||||
//supplier_invoice_pdf_create($db, $fac->id, $fac->modelpdf, $outputlangs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
@ -549,11 +596,11 @@ else
|
||||
print '<input size="30" name="libelle" type="text" value="'.$fac->libelle.'"></td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans('DateInvoice').'</td><td nowrap="nowrap">';
|
||||
$html->select_date($fac->datep,'','','','',"update");
|
||||
$html->select_date($fac->datep,'','','','',"update",1,1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans('DateEcheance').'</td><td nowrap="nowrap">';
|
||||
$html->select_date($fac->date_echeance,'ech','','','',"update");
|
||||
$html->select_date($fac->date_echeance,'ech','','','',"update",1,1);
|
||||
if (($fac->paye == 0) && ($fac->statut > 0) && $fac->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)) print img_picto($langs->trans("Late"),"warning");
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
@ -472,6 +472,8 @@ class FactureFournisseur extends Facture
|
||||
{
|
||||
global $conf,$langs;
|
||||
|
||||
$error=0;
|
||||
|
||||
// Protection
|
||||
if ($this->statut > 0) // This is to avoid to validate twice (avoid errors on logs and stock management)
|
||||
{
|
||||
@ -489,8 +491,6 @@ class FactureFournisseur extends Facture
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$error=0;
|
||||
|
||||
// Si activé on décrémente le produit principal et ses composants à la validation de facture
|
||||
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)
|
||||
{
|
||||
@ -540,21 +540,84 @@ class FactureFournisseur extends Facture
|
||||
|
||||
|
||||
/**
|
||||
* \brief Ajoute une ligne de facture (associ<EFBFBD> <EFBFBD> aucun produit/service pr<EFBFBD>d<EFBFBD>fini)
|
||||
* \brief Set draft status
|
||||
* \param user Object user that modify
|
||||
* \param int <0 if KO, >0 if OK
|
||||
*/
|
||||
function set_draft($user)
|
||||
{
|
||||
global $conf,$langs;
|
||||
|
||||
$error=0;
|
||||
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
dol_syslog("FactureFournisseur::set_draft already draft status", LOG_WARNING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
|
||||
$sql.= " SET fk_statut = 0";
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog("FactureFournisseur::set_draft sql=".$sql, LOG_DEBUG);
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
// Si active on decremente le produit principal et ses composants a la validation de facture
|
||||
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
|
||||
|
||||
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
|
||||
{
|
||||
if ($this->lignes[$i]->fk_product && $this->lignes[$i]->product_type == 0)
|
||||
{
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We increase stock for product
|
||||
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
|
||||
$result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($error == 0)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Ajoute une ligne de facture (associe a aucun produit/service predefini)
|
||||
* \param desc Description de la ligne
|
||||
* \param pu Prix unitaire (HT ou TTC selon price_base_type)
|
||||
* \param txtva Taux de tva forc<EFBFBD>, sinon -1
|
||||
* \param qty Quantit<EFBFBD>
|
||||
* \param fk_product Id du produit/service pred<EFBFBD>fini
|
||||
* \param txtva Taux de tva force, sinon -1
|
||||
* \param qty Quantite
|
||||
* \param fk_product Id du produit/service predefini
|
||||
* \param remise_percent Pourcentage de remise de la ligne
|
||||
* \param date_start Date de debut de validit<EFBFBD> du service
|
||||
* \param date_end Date de fin de validit<EFBFBD> du service
|
||||
* \param date_start Date de debut de validite du service
|
||||
* \param date_end Date de fin de validite du service
|
||||
* \param ventil Code de ventilation comptable
|
||||
* \param info_bits Bits de type de lignes
|
||||
* \param price_base_type HT ou TTC
|
||||
* \param type Type of line (0=product, 1=service)
|
||||
* \remarks Les parametres sont deja cens<EFBFBD> etre juste et avec valeurs finales a l'appel
|
||||
* de cette methode. Aussi, pour le taux tva, il doit deja avoir ete d<EFBFBD>fini
|
||||
* \remarks Les parametres sont deja cense etre juste et avec valeurs finales a l'appel
|
||||
* de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini
|
||||
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit)
|
||||
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user