diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index 9e05eb60909..283f4a264a4 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -74,7 +74,7 @@ class FactureFournisseur extends Facture
var $note_public;
var $propalid;
- var $lines;
+ var $lines;
var $fournisseur;
/**
@@ -101,7 +101,7 @@ class FactureFournisseur extends Facture
$this->propalid = 0;
$this->products = array();
- $this->lines = array();
+ $this->lines = array();
}
/**
@@ -352,7 +352,7 @@ class FactureFournisseur extends Facture
$this->lines[$i]->total_ttc = $obj->total_ttc;
$this->lines[$i]->fk_product = $obj->fk_product;
$this->lines[$i]->product_type = $obj->product_type;
-
+
$i++;
}
}
@@ -771,19 +771,19 @@ class FactureFournisseur extends Facture
}
/**
- * \brief Update line
- * \param id Id of line invoice
- * \param label Description of line
- * \param pu Prix unitaire (HT ou TTC selon price_base_type)
- * \param tauxtva VAT Rate
- * \param qty Quantity
- * \param idproduct Id produit
- * \param price_base_type HT or TTC
- * \param info_bits Miscellanous informations of line
- * \param type Type of line (0=product, 1=service)
- * \return int <0 if KO, >0 if OK
+ * Update a line detail into database
+ * @param id Id of line invoice
+ * @param label Description of line
+ * @param pu Prix unitaire (HT ou TTC selon price_base_type)
+ * @param vatrate VAT Rate
+ * @param qty Quantity
+ * @param idproduct Id produit
+ * @param price_base_type HT or TTC
+ * @param info_bits Miscellanous informations of line
+ * @param type Type of line (0=product, 1=service)
+ * @return int <0 if KO, >0 if OK
*/
- function updateline($id, $label, $pu, $tauxtva, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0)
+ function updateline($id, $label, $pu, $vatrate, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0)
{
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
@@ -794,11 +794,14 @@ class FactureFournisseur extends Facture
if (! is_numeric($pu) || ! is_numeric($qty)) return -1;
if ($type < 0) return -1;
+ // Clean parameters
+ if (empty($vatrate)) $vatrate=0;
+
// 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($qty, $pu, 0, $tauxtva, 0,0, 0, $price_base_type, $info_bits);
+ $tabprice = calcul_price_total($qty, $pu, 0, $vatrate, 0,0, 0, $price_base_type, $info_bits);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
$total_ttc = $tabprice[2];
@@ -822,7 +825,7 @@ class FactureFournisseur extends Facture
$sql.= ", pu_ht = ".price2num($pu_ht);
$sql.= ", pu_ttc = ".price2num($pu_ttc);
$sql.= ", qty = ".price2num($qty);
- $sql.= ", tva_tx = ".price2num($tauxtva);
+ $sql.= ", tva_tx = ".price2num($vatrate);
$sql.= ", total_ht = ".price2num($total_ht);
$sql.= ", tva= ".price2num($total_tva);
$sql.= ", total_ttc = ".price2num($total_ttc);
@@ -835,20 +838,22 @@ class FactureFournisseur extends Facture
$resql=$this->db->query($sql);
if ($resql)
{
- // Mise a jour prix total facture
- return $this->update_price();
+ // Update total price into invoice record
+ $result=$this->update_price();
+
+ return $result;
}
else
{
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
dol_syslog("Fournisseur.facture::updateline error=".$this->error, LOG_ERR);
return -1;
}
}
/**
- * \brief Supprime une ligne facture de la base
- * \param rowid id de la ligne de facture a supprimer
+ * Delete a detail line from database
+ * @param rowid id of line to delete
*/
function deleteline($rowid)
{
diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php
index 7bf2c8cf0c4..107bf2cc18e 100644
--- a/htdocs/fourn/facture/fiche.php
+++ b/htdocs/fourn/facture/fiche.php
@@ -24,7 +24,7 @@
/**
* \file htdocs/fourn/facture/fiche.php
* \ingroup facture, fournisseur
- * \brief Page for supplier invoice card
+ * \brief Page for supplier invoice card (view, edit, validate)
* \version $Id$
*/
@@ -61,125 +61,125 @@ $action=isset($_GET['action'])?$_GET['action']:$_POST['action'];
// Action clone object
if ($_REQUEST["action"] == 'confirm_clone' && $_REQUEST['confirm'] == 'yes')
{
- if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
- {
- $mesg='
'.$langs->trans("NoCloneOptionsSpecified").'
';
- }
- else
- {
- $object=new FactureFournisseur($db);
- $result=$object->createFromClone($_REQUEST['facid']);
- if ($result > 0)
- {
- header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result);
- exit;
- }
- else
- {
- $langs->load("errors");
- $mesg=''.$langs->trans($object->error).'
';
- $_GET['action']='';
- $_GET['id']=$_REQUEST['id'];
- }
- }
+ if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
+ {
+ $mesg=''.$langs->trans("NoCloneOptionsSpecified").'
';
+ }
+ else
+ {
+ $object=new FactureFournisseur($db);
+ $result=$object->createFromClone($_REQUEST['facid']);
+ if ($result > 0)
+ {
+ header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result);
+ exit;
+ }
+ else
+ {
+ $langs->load("errors");
+ $mesg=''.$langs->trans($object->error).'
';
+ $_GET['action']='';
+ $_GET['id']=$_REQUEST['id'];
+ }
+ }
}
if ($_REQUEST['action'] == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->facture->valider)
{
- $facturefourn=new FactureFournisseur($db);
- $facturefourn->fetch($_GET['facid']);
- $result = $facturefourn->validate($user);
- if ($result < 0)
- {
+ $facturefourn=new FactureFournisseur($db);
+ $facturefourn->fetch($_GET['facid']);
+ $result = $facturefourn->validate($user);
+ if ($result < 0)
+ {
$mesg=''.$facturefourn->error.'
';
- }
+ }
}
if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes')
{
- if ($user->rights->fournisseur->facture->supprimer )
- {
- $facturefourn = new FactureFournisseur($db);
- $factfournid = $_GET['facid'];
- $result=$facturefourn->delete($factfournid);
- if ($result > 0)
- {
- Header('Location: index.php');
- exit;
- }
- else
- {
- $mesg=''.$facturefourn->error.'
';
- }
- }
+ if ($user->rights->fournisseur->facture->supprimer )
+ {
+ $facturefourn = new FactureFournisseur($db);
+ $factfournid = $_GET['facid'];
+ $result=$facturefourn->delete($factfournid);
+ if ($result > 0)
+ {
+ Header('Location: index.php');
+ exit;
+ }
+ else
+ {
+ $mesg=''.$facturefourn->error.'
';
+ }
+ }
}
if ($_REQUEST['action'] == 'confirm_deleteproductline' && $_REQUEST['confirm'] == 'yes')
{
- if ($user->rights->fournisseur->facture->creer)
- {
- $facturefourn = new FactureFournisseur($db);
- $facturefourn->fetch($facid);
- $facturefourn->deleteline($_REQUEST['ligne_id']);
- $_GET['action'] = '';
- }
+ if ($user->rights->fournisseur->facture->creer)
+ {
+ $facturefourn = new FactureFournisseur($db);
+ $facturefourn->fetch($facid);
+ $facturefourn->deleteline($_REQUEST['lineid']);
+ $_GET['action'] = '';
+ }
}
if ($_REQUEST['action'] == 'confirm_paid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->facture->creer)
{
- $facturefourn=new FactureFournisseur($db);
- $facturefourn->fetch($_GET['facid']);
- $result=$facturefourn->set_paid($user);
+ $facturefourn=new FactureFournisseur($db);
+ $facturefourn->fetch($_GET['facid']);
+ $result=$facturefourn->set_paid($user);
}
// Set supplier ref
if (($_POST['action'] == 'setref_supplier' || $_POST['action'] == 'set_ref_supplier') && $user->rights->fournisseur->facture->creer)
{
- $facturefourn = new FactureFournisseur($db);
- $facturefourn->fetch($facid);
- $result=$facturefourn->set_ref_supplier($user, $_POST['ref_supplier']);
- $_GET['facid']=$facid;
+ $facturefourn = new FactureFournisseur($db);
+ $facturefourn->fetch($facid);
+ $result=$facturefourn->set_ref_supplier($user, $_POST['ref_supplier']);
+ $_GET['facid']=$facid;
}
if($_GET['action'] == 'deletepaiement')
{
- $facfou = new FactureFournisseur($db);
- $facfou->fetch($_GET['facid']);
- if ($facfou->statut == 1 && $facfou->paye == 0 && $user->societe_id == 0)
- {
- $paiementfourn = new PaiementFourn($db);
- $paiementfourn->fetch($_GET['paiement_id']);
- $paiementfourn->delete();
- }
+ $facfou = new FactureFournisseur($db);
+ $facfou->fetch($_GET['facid']);
+ if ($facfou->statut == 1 && $facfou->paye == 0 && $user->societe_id == 0)
+ {
+ $paiementfourn = new PaiementFourn($db);
+ $paiementfourn->fetch($_GET['paiement_id']);
+ $paiementfourn->delete();
+ }
}
if ($_POST['action'] == 'update' && ! $_POST['cancel'])
{
$error=0;
- $date = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- $date_echeance = dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']);
+ $date = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ $date_echeance = dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']);
- if (! $date)
- {
+ if (! $date)
+ {
$msg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEch"));
$error++;
- }
- if ($date_echeance && $date_echeance < $date)
+ }
+ if ($date_echeance && $date_echeance < $date)
{
$date_echeance = $date;
}
if (! $error)
{
- $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set ';
- $sql .= " facnumber='".$db->escape(trim($_POST['facnumber']))."'";
- $sql .= ", libelle='".$db->escape(trim($_POST['libelle']))."'";
- $sql .= ", note='".$db->escape($_POST['note'])."'";
- $sql .= ", datef = '".$db->idate($date)."'";
- $sql .= ", date_lim_reglement = '".$db->idate($date_echeance)."'";
- $sql .= ' WHERE rowid = '.$_GET['facid'].' ;';
- $result = $db->query($sql);
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set ';
+ $sql .= " facnumber='".$db->escape(trim($_POST['facnumber']))."'";
+ $sql .= ", libelle='".$db->escape(trim($_POST['libelle']))."'";
+ $sql .= ", note='".$db->escape($_POST['note'])."'";
+ $sql .= ", datef = '".$db->idate($date)."'";
+ $sql .= ", date_lim_reglement = '".$db->idate($date_echeance)."'";
+ $sql .= ' WHERE rowid = '.$_GET['facid'].' ;';
+ $result = $db->query($sql);
}
}
/*
@@ -187,300 +187,305 @@ if ($_POST['action'] == 'update' && ! $_POST['cancel'])
*/
if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
{
- $datefacture=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
- $datedue=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
+ $datefacture=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
+ $datedue=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
- if ($datefacture == '')
- {
- $mesg=''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('DateInvoice')).'
';
- $_GET['action']='create';
- $_GET['socid']=$_POST['socid'];
- $error++;
- }
- if (empty($_POST['facnumber']))
- {
- $mesg=''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'
';
- $_GET['action']='create';
- $_GET['socid']=$_POST['socid'];
- $error++;
- }
+ if ($datefacture == '')
+ {
+ $mesg=''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('DateInvoice')).'
';
+ $_GET['action']='create';
+ $_GET['socid']=$_POST['socid'];
+ $error++;
+ }
+ if (empty($_POST['facnumber']))
+ {
+ $mesg=''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'
';
+ $_GET['action']='create';
+ $_GET['socid']=$_POST['socid'];
+ $error++;
+ }
- if (! $error)
- {
- $db->begin();
+ if (! $error)
+ {
+ $db->begin();
- // Creation facture
- $facfou = new FactureFournisseur($db);
+ // Creation facture
+ $facfou = new FactureFournisseur($db);
- $facfou->ref = $_POST['facnumber'];
- $facfou->socid = $_POST['socid'];
- $facfou->libelle = $_POST['libelle'];
- $facfou->date = $datefacture;
- $facfou->date_echeance = $datedue;
- $facfou->note_public = $_POST['note'];
+ $facfou->ref = $_POST['facnumber'];
+ $facfou->socid = $_POST['socid'];
+ $facfou->libelle = $_POST['libelle'];
+ $facfou->date = $datefacture;
+ $facfou->date_echeance = $datedue;
+ $facfou->note_public = $_POST['note'];
- $facid = $facfou->create($user);
+ $facid = $facfou->create($user);
- // Ajout des lignes de factures
- if ($facid > 0)
- {
- for ($i = 1 ; $i < 9 ; $i++)
- {
- $label = $_POST['label'.$i];
- $amountht = price2num($_POST['amount'.$i]);
- $amountttc = price2num($_POST['amountttc'.$i]);
- $tauxtva = price2num($_POST['tauxtva'.$i]);
- $qty = $_POST['qty'.$i];
- $fk_product = $_POST['fk_product'.$i];
- if ($label)
- {
- if ($amountht)
- {
- $price_base='HT'; $amount=$amountht;
- }
- else
- {
- $price_base='TTC'; $amount=$amountttc;
- }
- $atleastoneline=1;
- $ret=$facfou->addline($label, $amount, $tauxtva, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base);
- if ($ret < 0) $nberror++;
- }
- }
- if ($nberror)
- {
- $db->rollback();
- $mesg=''.$facfou->error.'
';
- $_GET['action']='create';
- $_GET['socid']=$_POST['socid'];
- }
- else
- {
- $db->commit();
- header('Location: fiche.php?facid='.$facid);
- exit;
- }
- }
- else
- {
- $db->rollback();
- $mesg=''.$facfou->error.'
';
- $_GET['action']='create';
- $_GET['socid']=$_POST['socid'];
- }
- }
+ // Ajout des lignes de factures
+ if ($facid > 0)
+ {
+ for ($i = 1 ; $i < 9 ; $i++)
+ {
+ $label = $_POST['label'.$i];
+ $amountht = price2num($_POST['amount'.$i]);
+ $amountttc = price2num($_POST['amountttc'.$i]);
+ $tauxtva = price2num($_POST['tauxtva'.$i]);
+ $qty = $_POST['qty'.$i];
+ $fk_product = $_POST['fk_product'.$i];
+ if ($label)
+ {
+ if ($amountht)
+ {
+ $price_base='HT'; $amount=$amountht;
+ }
+ else
+ {
+ $price_base='TTC'; $amount=$amountttc;
+ }
+ $atleastoneline=1;
+ $ret=$facfou->addline($label, $amount, $tauxtva, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base);
+ if ($ret < 0) $nberror++;
+ }
+ }
+ if ($nberror)
+ {
+ $db->rollback();
+ $mesg=''.$facfou->error.'
';
+ $_GET['action']='create';
+ $_GET['socid']=$_POST['socid'];
+ }
+ else
+ {
+ $db->commit();
+ header('Location: fiche.php?facid='.$facid);
+ exit;
+ }
+ }
+ else
+ {
+ $db->rollback();
+ $mesg=''.$facfou->error.'
';
+ $_GET['action']='create';
+ $_GET['socid']=$_POST['socid'];
+ }
+ }
}
if ($_GET['action'] == 'del_ligne')
{
- $facfou = new FactureFournisseur($db,'',$_GET['facid']);
- $facfou->deleteline($_GET['ligne_id']);
- $_GET['action'] = 'edit';
+ $facfou = new FactureFournisseur($db,'',$_GET['facid']);
+ $facfou->deleteline($_GET['lineid']);
+ $_GET['action'] = 'edit';
}
// Modification d'une ligne
if ($_REQUEST['action'] == 'update_line')
{
- if ($_REQUEST['etat'] == '1' && ! $_REQUEST['cancel']) // si on valide la modification
- {
- $facfou = new FactureFournisseur($db);
- $facfou->fetch($_GET['facid']);
+ if ($_REQUEST['etat'] == '1' && ! $_REQUEST['cancel']) // si on valide la modification
+ {
+ $facfou = new FactureFournisseur($db);
+ $facfou->fetch($_GET['facid']);
- if ($_POST['puht'])
- {
- $pu=$_POST['puht'];
- $price_base_type='HT';
- }
- if ($_POST['puttc'])
- {
- $pu=$_POST['puttc'];
- $price_base_type='TTC';
- }
+ if ($_POST['puht'])
+ {
+ $pu=$_POST['puht'];
+ $price_base_type='HT';
+ }
+ if ($_POST['puttc'])
+ {
+ $pu=$_POST['puttc'];
+ $price_base_type='TTC';
+ }
- if ($_POST['idprod'])
- {
- $prod = new Product($db);
- $prod->fetch($_POST['idprod']);
- $label = $prod->libelle;
- $type = $prod->type;
- }
- else
- {
- $label = $_POST['label'];
- $type = $_POST["type"]?$_POST["type"]:0;
- }
+ if ($_POST['idprod'])
+ {
+ $prod = new Product($db);
+ $prod->fetch($_POST['idprod']);
+ $label = $prod->libelle;
+ $type = $prod->type;
+ }
+ else
+ {
+ $label = $_POST['label'];
+ $type = $_POST["type"]?$_POST["type"]:0;
+ }
- $facfou->updateline($_GET['ligne_id'], $label, $pu, $_POST['tauxtva'], $_POST['qty'], $_POST['idprod'], $price_base_type, 0, $type);
- }
+ $result=$facfou->updateline($_GET['lineid'], $label, $pu, $_POST['tauxtva'], $_POST['qty'], $_POST['idprod'], $price_base_type, 0, $type);
+ if ($result >= 0)
+ {
+ unset($_POST['label']);
+ }
+ }
}
if ($_GET['action'] == 'addline')
{
- $facfou = new FactureFournisseur($db, '', $_GET['facid']);
- $ret=$facfou->fetch($_GET['facid']);
- if ($ret < 0)
- {
- dol_print_error($db,$facfou->error);
- exit;
- }
+ $facfou = new FactureFournisseur($db, '', $_GET['facid']);
+ $ret=$facfou->fetch($_GET['facid']);
+ if ($ret < 0)
+ {
+ dol_print_error($db,$facfou->error);
+ exit;
+ }
- if ($_POST['idprodfournprice']) // > 0 or -1
- {
- $product = new ProductFournisseur($db);
- $idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']);
- if ($idprod > 0)
- {
- $result=$product->fetch($idprod);
+ if ($_POST['idprodfournprice']) // > 0 or -1
+ {
+ $product = new ProductFournisseur($db);
+ $idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']);
+ if ($idprod > 0)
+ {
+ $result=$product->fetch($idprod);
- // cas special pour lequel on a les meme reference que le fournisseur
- // $label = '['.$product->ref.'] - '. $product->libelle;
- $label = $product->libelle;
+ // cas special pour lequel on a les meme reference que le fournisseur
+ // $label = '['.$product->ref.'] - '. $product->libelle;
+ $label = $product->libelle;
- $societe='';
- if ($facfou->socid)
- {
- $societe=new Societe($db);
- $societe->fetch($facfou->socid);
- }
+ $societe='';
+ if ($facfou->socid)
+ {
+ $societe=new Societe($db);
+ $societe->fetch($facfou->socid);
+ }
- $tvatx=get_default_tva($societe,$mysoc,$product->id);
- $type = $product->type;
+ $tvatx=get_default_tva($societe,$mysoc,$product->id);
+ $type = $product->type;
- $result=$facfou->addline($label, $product->fourn_pu, $tvatx, $_POST['qty'], $idprod);
- }
- if ($idprod == -1)
- {
- // Quantity too low
- $langs->load("errors");
- $mesg=''.$langs->trans("ErrorQtyTooLowForThisSupplier").'
';
- }
- }
- else
- {
- $tauxtva = price2num($_POST['tauxtva']);
- if (! $_POST['label'])
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
';
- }
- else
- {
- $type = $_POST["type"];
- if (! empty($_POST['amount']))
- {
- $ht = price2num($_POST['amount']);
- $price_base_type = 'HT';
- //$desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0)
- $result=$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty'], 0, 0, $datestart, $dateend, 0, 0, $price_base_type, $type);
- }
- else
- {
- $ttc = price2num($_POST['amountttc']);
- $ht = $ttc / (1 + ($tauxtva / 100));
- $price_base_type = 'HT';
- $result=$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty'], 0, 0, $datestart, $dateend, 0, 0, $price_base_type, $type);
- }
- }
- }
+ $result=$facfou->addline($label, $product->fourn_pu, $tvatx, $_POST['qty'], $idprod);
+ }
+ if ($idprod == -1)
+ {
+ // Quantity too low
+ $langs->load("errors");
+ $mesg=''.$langs->trans("ErrorQtyTooLowForThisSupplier").'
';
+ }
+ }
+ else
+ {
+ $tauxtva = price2num($_POST['tauxtva']);
+ if (! $_POST['label'])
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
';
+ }
+ else
+ {
+ $type = $_POST["type"];
+ if (! empty($_POST['amount']))
+ {
+ $ht = price2num($_POST['amount']);
+ $price_base_type = 'HT';
+ //$desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0)
+ $result=$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty'], 0, 0, $datestart, $dateend, 0, 0, $price_base_type, $type);
+ }
+ else
+ {
+ $ttc = price2num($_POST['amountttc']);
+ $ht = $ttc / (1 + ($tauxtva / 100));
+ $price_base_type = 'HT';
+ $result=$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty'], 0, 0, $datestart, $dateend, 0, 0, $price_base_type, $type);
+ }
+ }
+ }
- //print "xx".$tva_tx; exit;
- if ($result > 0)
- {
- $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);
+ //print "xx".$tva_tx; exit;
+ if ($result > 0)
+ {
+ $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);
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['idprodfournprice']);
- unset($_POST['remmise_percent']);
- unset($_POST['dp_desc']);
- unset($_POST['np_desc']);
- unset($_POST['pu']);
- unset($_POST['tva_tx']);
- }
- else if (empty($mesg))
- {
- $mesg=''.$facfou->error.'
';
- }
+ unset($_POST['qty']);
+ unset($_POST['type']);
+ unset($_POST['idprodfournprice']);
+ unset($_POST['remmise_percent']);
+ unset($_POST['dp_desc']);
+ unset($_POST['np_desc']);
+ unset($_POST['pu']);
+ unset($_POST['tva_tx']);
+ unset($_POST['label']);
+ }
+ else if (empty($mesg))
+ {
+ $mesg=''.$facfou->error.'
';
+ }
- $_GET['action'] = '';
+ $_GET['action'] = '';
}
if ($_POST['action'] == 'classin')
{
- $facture = new FactureFournisseur($db,'',$_GET['facid']);
- $facture->fetch($_GET['facid']);
- $result=$facture->setProject($_POST['projectid']);
+ $facture = new FactureFournisseur($db,'',$_GET['facid']);
+ $facture->fetch($_GET['facid']);
+ $result=$facture->setProject($_POST['projectid']);
}
// Repasse la facture en mode brouillon
if ($_GET['action'] == 'edit' && $user->rights->fournisseur->facture->creer)
{
- $fac = new FactureFournisseur($db);
- $fac->fetch($_GET['facid']);
+ $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;
+ // 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);
+ $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++;
- }
- }
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($result);
+ $totalpaye += $objp->amount;
+ $i++;
+ }
+ }
- $resteapayer = $fac->total_ttc - $totalpaye;
+ $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 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);
+ // 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);
- }
+ $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);
+ }
}
if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->facture->creer)
{
- $fac = new FactureFournisseur($db);
- $result = $fac->fetch($_GET['facid']);
- if ($fac->statut == 2
- || ($fac->statut == 3 && $fac->close_code != 'replaced'))
- {
- $result = $fac->set_unpaid($user);
- if ($result > 0)
- {
- Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']);
- exit;
- }
- else
- {
- $mesg=''.$fac->error.'
';
- }
- }
+ $fac = new FactureFournisseur($db);
+ $result = $fac->fetch($_GET['facid']);
+ if ($fac->statut == 2
+ || ($fac->statut == 3 && $fac->close_code != 'replaced'))
+ {
+ $result = $fac->set_unpaid($user);
+ if ($result > 0)
+ {
+ Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']);
+ exit;
+ }
+ else
+ {
+ $mesg=''.$fac->error.'
';
+ }
+ }
}
@@ -495,16 +500,16 @@ if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->facture->creer)
*/
if ($_POST['addfile'])
{
- require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
- // Set tmp user directory TODO Use a dedicated directory for temp mails files
- $vardir=$conf->user->dir_output."/".$user->id;
- $upload_dir = $vardir.'/temp/';
+ // Set tmp user directory TODO Use a dedicated directory for temp mails files
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir = $vardir.'/temp/';
- $mesg=dol_add_file_process($upload_dir,0,0);
+ $mesg=dol_add_file_process($upload_dir,0,0);
- $_GET["action"]='presend';
- $_POST["action"]='presend';
+ $_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -512,16 +517,16 @@ if ($_POST['addfile'])
*/
if (! empty($_POST['removedfile']))
{
- require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
- // Set tmp user directory
- $vardir=$conf->user->dir_output."/".$user->id;
- $upload_dir = $vardir.'/temp/';
+ // Set tmp user directory
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir = $vardir.'/temp/';
- $mesg=dol_remove_file_process($_POST['removedfile'],0);
+ $mesg=dol_remove_file_process($_POST['removedfile'],0);
- $_GET["action"]='presend';
- $_POST["action"]='presend';
+ $_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -529,155 +534,155 @@ if (! empty($_POST['removedfile']))
*/
if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
{
- $langs->load('mails');
+ $langs->load('mails');
- $facturefourn=new FactureFournisseur($db);
- $facturefourn->fetch($_GET['facid']);
- $result=$facturefourn->fetch_thirdparty();
- if ($result > 0)
- {
- $ref = dol_sanitizeFileName($facturefourn->ref);
- $file = $conf->fournisseur->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
+ $facturefourn=new FactureFournisseur($db);
+ $facturefourn->fetch($_GET['facid']);
+ $result=$facturefourn->fetch_thirdparty();
+ if ($result > 0)
+ {
+ $ref = dol_sanitizeFileName($facturefourn->ref);
+ $file = $conf->fournisseur->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
- if (is_readable($file))
- {
- if ($_POST['sendto'])
- {
- // Le destinataire a ete fourni via le champ libre
- $sendto = $_POST['sendto'];
- $sendtoid = 0;
- }
- elseif ($_POST['receiver'])
- {
- // Le destinataire a ete fourni via la liste deroulante
- if ($_POST['receiver'] < 0) // Id du tiers
- {
- $sendto = $facturefourn->client->email;
- $sendtoid = 0;
- }
- else // Id du contact
- {
- $sendto = $facturefourn->client->contact_get_email($_POST['receiver']);
- $sendtoid = $_POST['receiver'];
- }
- }
+ if (is_readable($file))
+ {
+ if ($_POST['sendto'])
+ {
+ // Le destinataire a ete fourni via le champ libre
+ $sendto = $_POST['sendto'];
+ $sendtoid = 0;
+ }
+ elseif ($_POST['receiver'])
+ {
+ // Le destinataire a ete fourni via la liste deroulante
+ if ($_POST['receiver'] < 0) // Id du tiers
+ {
+ $sendto = $facturefourn->client->email;
+ $sendtoid = 0;
+ }
+ else // Id du contact
+ {
+ $sendto = $facturefourn->client->contact_get_email($_POST['receiver']);
+ $sendtoid = $_POST['receiver'];
+ }
+ }
- if (dol_strlen($sendto))
- {
- $langs->load("commercial");
+ if (dol_strlen($sendto))
+ {
+ $langs->load("commercial");
- $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
- $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
- $message = $_POST['message'];
- $sendtocc = $_POST['sendtocc'];
- $deliveryreceipt = $_POST['deliveryreceipt'];
+ $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
+ $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
+ $message = $_POST['message'];
+ $sendtocc = $_POST['sendtocc'];
+ $deliveryreceipt = $_POST['deliveryreceipt'];
- if ($_POST['action'] == 'send')
- {
- if (dol_strlen($_POST['subject'])) $subject=$_POST['subject'];
- else $subject = $langs->transnoentities('CustomerOrder').' '.$facturefourn->ref;
- $actiontypecode='AC_SUP_ORD';
- $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
- if ($message)
- {
- $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
- $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
- $actionmsg.=$message;
- }
- $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
- }
+ if ($_POST['action'] == 'send')
+ {
+ if (dol_strlen($_POST['subject'])) $subject=$_POST['subject'];
+ else $subject = $langs->transnoentities('CustomerOrder').' '.$facturefourn->ref;
+ $actiontypecode='AC_SUP_ORD';
+ $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
+ if ($message)
+ {
+ $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
+ $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
+ $actionmsg.=$message;
+ }
+ $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
+ }
- // Create form object
- include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
+ // Create form object
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
+ $formmail = new FormMail($db);
- $attachedfiles=$formmail->get_attached_files();
- $filepath = $attachedfiles['paths'];
- $filename = $attachedfiles['names'];
- $mimetype = $attachedfiles['mimes'];
+ $attachedfiles=$formmail->get_attached_files();
+ $filepath = $attachedfiles['paths'];
+ $filename = $attachedfiles['names'];
+ $mimetype = $attachedfiles['mimes'];
- // Send mail
- require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php');
- $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
- if ($mailfile->error)
- {
- $mesg=''.$mailfile->error.'
';
- }
- else
- {
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=''.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
';
+ // Send mail
+ require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php');
+ $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
+ if ($mailfile->error)
+ {
+ $mesg=''.$mailfile->error.'
';
+ }
+ else
+ {
+ $result=$mailfile->sendfile();
+ if ($result)
+ {
+ $mesg=''.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
';
- $error=0;
+ $error=0;
- // Initialisation donnees
- $facturefourn->sendtoid=$sendtoid;
- $facturefourn->actiontypecode=$actiontypecode;
- $facturefourn->actionmsg = $actionmsg;
- $facturefourn->actionmsg2= $actionmsg2;
- $facturefourn->supplierorderrowid=$facturefourn->id;
+ // Initialisation donnees
+ $facturefourn->sendtoid=$sendtoid;
+ $facturefourn->actiontypecode=$actiontypecode;
+ $facturefourn->actionmsg = $actionmsg;
+ $facturefourn->actionmsg2= $actionmsg2;
+ $facturefourn->supplierorderrowid=$facturefourn->id;
- // Appel des triggers
- include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
- $interface=new Interfaces($db);
- $result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$facturefourn,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // Fin appel triggers
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($db);
+ $result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$facturefourn,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // Fin appel triggers
- if ($error)
- {
- dol_print_error($db);
- }
- else
- {
- // Redirect here
- // This avoid sending mail twice if going out and then back to page
- Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facturefourn->id.'&mesg='.urlencode($mesg));
- exit;
- }
- }
- else
- {
- $langs->load("other");
- $mesg='';
- if ($mailfile->error)
- {
- $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
- $mesg.=' '.$mailfile->error;
- }
- else
- {
- $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
- }
- $mesg.='
';
- }
- }
- }
-
- else
- {
- $langs->load("other");
- $mesg=''.$langs->trans('ErrorMailRecipientIsEmpty').'
';
- dol_syslog('Recipient email is empty');
- }
- }
- else
- {
- $langs->load("other");
- $mesg=''.$langs->trans('ErrorCantReadFile',$file).'
';
- dol_syslog('Failed to read file: '.$file);
- }
- }
- else
- {
- $langs->load("other");
- $mesg=''.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
';
- dol_syslog('Unable to read data from the invoice. The invoice file has perhaps not been generated.');
- }
+ if ($error)
+ {
+ dol_print_error($db);
+ }
+ else
+ {
+ // Redirect here
+ // This avoid sending mail twice if going out and then back to page
+ Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facturefourn->id.'&mesg='.urlencode($mesg));
+ exit;
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg='';
+ if ($mailfile->error)
+ {
+ $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
+ $mesg.=' '.$mailfile->error;
+ }
+ else
+ {
+ $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
+ }
+ $mesg.='
';
+ }
+ }
+ }
- //$_GET['action'] = 'presend';
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorMailRecipientIsEmpty').'
';
+ dol_syslog('Recipient email is empty');
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorCantReadFile',$file).'
';
+ dol_syslog('Failed to read file: '.$file);
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
';
+ dol_syslog('Unable to read data from the invoice. The invoice file has perhaps not been generated.');
+ }
+
+ //$_GET['action'] = 'presend';
}
/*
@@ -686,50 +691,50 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
if ($_REQUEST['action'] == 'builddoc')
{
- /*
- * Generation de la facture
- * definit dans /includes/modules/supplier_invoice/modules_facturefournisseur.php
- */
+ /*
+ * Generation de la facture
+ * definit dans /includes/modules/supplier_invoice/modules_facturefournisseur.php
+ */
- // Sauvegarde le dernier module choisi pour generer un document
- $facture= new FactureFournisseur($db);
- $facture->fetch($_REQUEST['facid']);
- if ($_REQUEST['model'])
- {
- $facture->setDocModel($user, $_REQUEST['model']);
- }
+ // Sauvegarde le dernier module choisi pour generer un document
+ $facture= new FactureFournisseur($db);
+ $facture->fetch($_REQUEST['facid']);
+ if ($_REQUEST['model'])
+ {
+ $facture->setDocModel($user, $_REQUEST['model']);
+ }
- $outputlangs = $langs;
- if (! empty($_REQUEST['lang_id']))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- $result=supplier_invoice_pdf_create($db, $facture,$facture->modelpdf,$outputlangs);
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
- }
- else
- {
- Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facture->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
- exit;
- }
+ $outputlangs = $langs;
+ if (! empty($_REQUEST['lang_id']))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ $result=supplier_invoice_pdf_create($db, $facture,$facture->modelpdf,$outputlangs);
+ if ($result <= 0)
+ {
+ dol_print_error($db,$result);
+ exit;
+ }
+ else
+ {
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facture->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
+ exit;
+ }
}
// Delete file in doc form
if ($action=='remove_file')
{
- $facture = new FactureFournisseur($db);
+ $facture = new FactureFournisseur($db);
- if ($facture->fetch($id))
- {
- $upload_dir = $conf->fournisseur->facture->dir_output . "/";
- $file = $upload_dir . '/' . $_GET['file'];
- dol_delete_file($file);
- $mesg = ''.$langs->trans("FileWasRemoved").'
';
- }
+ if ($facture->fetch($id))
+ {
+ $upload_dir = $conf->fournisseur->facture->dir_output . "/";
+ $file = $upload_dir . '/' . $_GET['file'];
+ dol_delete_file($file);
+ $mesg = ''.$langs->trans("FileWasRemoved").'
';
+ }
}
@@ -745,867 +750,867 @@ $formfile = new FormFile($db);
// Mode creation
if ($_GET['action'] == 'create')
{
- print_fiche_titre($langs->trans('NewBill'));
+ print_fiche_titre($langs->trans('NewBill'));
- if ($mesg) { print $mesg.' '; }
+ if ($mesg) { print $mesg.' '; }
- $societe='';
- if ($_GET['socid'])
- {
- $societe=new Societe($db);
- $societe->fetch($_GET['socid']);
- }
+ $societe='';
+ if ($_GET['socid'])
+ {
+ $societe=new Societe($db);
+ $societe->fetch($_GET['socid']);
+ }
- $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
- $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datetmp);
- $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
- $datedue=($datetmp==''?-1:$datetmp);
+ $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
+ $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datetmp);
+ $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
+ $datedue=($datetmp==''?-1:$datetmp);
- print '';
+ print ' ';
+ print '';
}
else
{
- if ($_GET['facid'] > 0)
- {
- /* *************************************************************************** */
- /* */
- /* Fiche en mode visu ou edition */
- /* */
- /* *************************************************************************** */
+ if ($_GET['facid'] > 0)
+ {
+ /* *************************************************************************** */
+ /* */
+ /* Fiche en mode visu ou edition */
+ /* */
+ /* *************************************************************************** */
- $now=dol_now();
+ $now=dol_now();
- $productstatic = new Product($db);
+ $productstatic = new Product($db);
- $fac = new FactureFournisseur($db);
- $fac->fetch($_GET['facid']);
+ $fac = new FactureFournisseur($db);
+ $fac->fetch($_GET['facid']);
- $societe = new Fournisseur($db);
- $societe->fetch($fac->socid);
+ $societe = new Fournisseur($db);
+ $societe->fetch($fac->socid);
- if ($_GET['action'] == 'edit')
- {
- print_fiche_titre($langs->trans('SupplierInvoice'));
+ if ($_GET['action'] == 'edit')
+ {
+ print_fiche_titre($langs->trans('SupplierInvoice'));
- print '';
- print ' ';
- print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
- print '';
+ print '';
- print ''.$langs->trans('Company').' ';
- print ''.$societe->getNomUrl(1).' ';
- print ''.$langs->trans('NotePublic').' ';
- print ' ';
+ print ''.$langs->trans('Company').' ';
+ print ''.$societe->getNomUrl(1).' ';
+ print ''.$langs->trans('NotePublic').' ';
+ print ' ';
- // Ref
- print ''.$langs->trans('Ref').' ';
- print $fac->ref.' ';
- $rownb=10;
- print '';
- print '';
- print $fac->note;
- print ' ';
+ // Ref
+ print ''.$langs->trans('Ref').' ';
+ print $fac->ref.' ';
+ $rownb=10;
+ print '';
+ print '';
+ print $fac->note;
+ print ' ';
- // Ref supplier
- print ''.$langs->trans('RefSupplier').' ';
- print ' ';
- print ' ';
+ // Ref supplier
+ print ''.$langs->trans('RefSupplier').' ';
+ print ' ';
+ print ' ';
- // Label
- print ''.$langs->trans('Label').' ';
- print ' ';
+ // Label
+ print ''.$langs->trans('Label').' ';
+ print ' ';
- // Date invoice
- print ''.$langs->trans('DateInvoice').' ';
- $html->select_date($fac->datep,'','','','',"update",1,1);
- print ' ';
+ // Date invoice
+ print ''.$langs->trans('DateInvoice').' ';
+ $html->select_date($fac->datep,'','','','',"update",1,1);
+ print ' ';
- // Due date
- print ''.$langs->trans('DateEcheance').' ';
- $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 ' ';
+ // Due date
+ print ''.$langs->trans('DateEcheance').' ';
+ $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 ' ';
- print ''.$langs->trans('AmountHT').' '.price($fac->total_ht).' ';
- print ''.$langs->trans('AmountVAT').' '.price($fac->total_tva).' ';
- print ''.$langs->trans('AmountTTC').' '.price($fac->total_ttc).' ';
+ print ''.$langs->trans('AmountHT').' '.price($fac->total_ht).' ';
+ print ''.$langs->trans('AmountVAT').' '.price($fac->total_tva).' ';
+ print ''.$langs->trans('AmountTTC').' '.price($fac->total_ttc).' ';
- print ''.$langs->trans('Status').' '.$fac->getLibStatut(4).' ';
- print '';
- print ' ';
- print ' ';
- print ' ';
+ print ' '.$langs->trans('Status').' '.$fac->getLibStatut(4).' ';
+ print '';
+ print ' ';
+ print ' ';
+ print ' ';
- print ' ';
- print '
';
- print '';
+ print '';
+ print '
';
+ print ' ';
- print '';
- }
- else
- {
- /*
- * View card
- */
- $head = facturefourn_prepare_head($fac);
- $titre=$langs->trans('SupplierInvoice');
- dol_fiche_head($head, 'card', $titre, 0, 'bill');
+ print '';
+ }
+ else
+ {
+ /*
+ * View card
+ */
+ $head = facturefourn_prepare_head($fac);
+ $titre=$langs->trans('SupplierInvoice');
+ dol_fiche_head($head, 'card', $titre, 0, 'bill');
- if ($mesg) { print $mesg.' '; }
+ if ($mesg) { print $mesg.' '; }
- // Confirmation de la suppression d'une ligne produit
- if ($_GET['action'] == 'confirm_delete_line')
- {
- $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id.'&ligne_id='.$_GET["ligne_id"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline', '', 1, 1);
- if ($ret == 'html') print ' ';
- }
+ // Confirmation de la suppression d'une ligne produit
+ if ($_GET['action'] == 'confirm_delete_line')
+ {
+ $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline', '', 1, 1);
+ if ($ret == 'html') print ' ';
+ }
- // Clone confirmation
- if ($_GET["action"] == 'clone')
- {
- // Create an array for form
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
- );
- // Paiement incomplet. On demande si motif = escompte ou autre
- $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$fac->ref),'confirm_clone',$formquestion,'yes', 1);
- if ($ret == 'html') print ' ';
- }
+ // Clone confirmation
+ if ($_GET["action"] == 'clone')
+ {
+ // Create an array for form
+ $formquestion=array(
+ //'text' => $langs->trans("ConfirmClone"),
+ //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
+ );
+ // Paiement incomplet. On demande si motif = escompte ou autre
+ $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$fac->ref),'confirm_clone',$formquestion,'yes', 1);
+ if ($ret == 'html') print ' ';
+ }
- // Confirmation de la validation
- if ($_GET['action'] == 'valid')
- {
- $ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('ValidateBill'), $langs->trans('ConfirmValidateBill', $fac->ref), 'confirm_valid', '', 0, 1);
- if ($ret == 'html') print ' ';
- }
+ // Confirmation de la validation
+ if ($_GET['action'] == 'valid')
+ {
+ $ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('ValidateBill'), $langs->trans('ConfirmValidateBill', $fac->ref), 'confirm_valid', '', 0, 1);
+ if ($ret == 'html') print ' ';
+ }
- // Confirmation set paid
- if ($_GET['action'] == 'paid')
- {
- $ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $fac->ref), 'confirm_paid', '', 0, 1);
- if ($ret == 'html') print ' ';
- }
+ // Confirmation set paid
+ if ($_GET['action'] == 'paid')
+ {
+ $ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $fac->ref), 'confirm_paid', '', 0, 1);
+ if ($ret == 'html') print ' ';
+ }
- /*
- * Confirmation de la suppression de la facture fournisseur
- */
- if ($_GET['action'] == 'delete')
- {
- $ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
- if ($ret == 'html') print ' ';
- }
+ /*
+ * Confirmation de la suppression de la facture fournisseur
+ */
+ if ($_GET['action'] == 'delete')
+ {
+ $ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
+ if ($ret == 'html') print ' ';
+ }
- /*
- * Facture
- */
- print '';
+ /*
+ * Facture
+ */
+ print '';
- // Ref
- print ''.$langs->trans("Ref").' ';
- print $html->showrefnav($fac,'facid','',1,'rowid','ref',$morehtmlref);
- print ' ';
- print " \n";
+ // Ref
+ print ''.$langs->trans("Ref").' ';
+ print $html->showrefnav($fac,'facid','',1,'rowid','ref',$morehtmlref);
+ print ' ';
+ print " \n";
// Ref supplier
print ''.$html->editfieldkey("RefSupplier",'ref_supplier',$fac->ref_supplier,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer)).' ';
print $html->editfieldval("RefSupplier",'ref_supplier',$fac->ref_supplier,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer));
print ' ';
- // Third party
- print ''.$langs->trans('Supplier').' '.$societe->getNomUrl(1);
- print ' ('.$langs->trans('OtherBills').' ) ';
- print ' ';
+ // Third party
+ print ''.$langs->trans('Supplier').' '.$societe->getNomUrl(1);
+ print ' ('.$langs->trans('OtherBills').' ) ';
+ print ' ';
- // Type
- print ''.$langs->trans('Type').' ';
- print $fac->getLibType();
- if ($fac->type == 1)
- {
- $facreplaced=new FactureFournisseur($db);
- $facreplaced->fetch($fac->fk_facture_source);
- print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
- }
- if ($fac->type == 2)
- {
- $facusing=new FactureFournisseur($db);
- $facusing->fetch($fac->fk_facture_source);
- print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
- }
+ // Type
+ print ' '.$langs->trans('Type').' ';
+ print $fac->getLibType();
+ if ($fac->type == 1)
+ {
+ $facreplaced=new FactureFournisseur($db);
+ $facreplaced->fetch($fac->fk_facture_source);
+ print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
+ }
+ if ($fac->type == 2)
+ {
+ $facusing=new FactureFournisseur($db);
+ $facusing->fetch($fac->fk_facture_source);
+ print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
+ }
- $facidavoir=$fac->getListIdAvoirFromInvoice();
- if (sizeof($facidavoir) > 0)
- {
- print ' ('.$langs->transnoentities("InvoiceHasAvoir");
- $i=0;
- foreach($facidavoir as $id)
- {
- if ($i==0) print ' ';
- else print ',';
- $facavoir=new FactureFournisseur($db);
- $facavoir->fetch($id);
- print $facavoir->getNomUrl(1);
- }
- print ')';
- }
- if ($facidnext > 0)
- {
- $facthatreplace=new FactureFournisseur($db);
- $facthatreplace->fetch($facidnext);
- print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
- }
- print ' ';
+ $facidavoir=$fac->getListIdAvoirFromInvoice();
+ if (sizeof($facidavoir) > 0)
+ {
+ print ' ('.$langs->transnoentities("InvoiceHasAvoir");
+ $i=0;
+ foreach($facidavoir as $id)
+ {
+ if ($i==0) print ' ';
+ else print ',';
+ $facavoir=new FactureFournisseur($db);
+ $facavoir->fetch($id);
+ print $facavoir->getNomUrl(1);
+ }
+ print ')';
+ }
+ if ($facidnext > 0)
+ {
+ $facthatreplace=new FactureFournisseur($db);
+ $facthatreplace->fetch($facidnext);
+ print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
+ }
+ print '';
- // Label
- print ''.$langs->trans('Label').' ';
- print $fac->libelle;
- print ' ';
+ // Label
+ print ''.$langs->trans('Label').' ';
+ print $fac->libelle;
+ print ' ';
- /*
- * List of payments
- */
- $nbrows=7;
- if ($conf->projet->enabled) $nbrows++;
+ /*
+ * List of payments
+ */
+ $nbrows=7;
+ if ($conf->projet->enabled) $nbrows++;
- // Local taxes
- if ($mysoc->pays_code=='ES')
- {
- if($mysoc->localtax1_assuj=="1") $nbrow++;
- if($mysoc->localtax2_assuj=="1") $nbrow++;
- }
+ // Local taxes
+ if ($mysoc->pays_code=='ES')
+ {
+ if($mysoc->localtax1_assuj=="1") $nbrow++;
+ if($mysoc->localtax2_assuj=="1") $nbrow++;
+ }
- print '';
- $sql = 'SELECT datep as dp, pf.amount,';
- $sql .= ' c.libelle as paiement_type, p.num_paiement, p.rowid';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p';
- $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
- $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
- $sql .= ' WHERE pf.fk_facturefourn = '.$fac->id;
- $sql .= ' ORDER BY dp DESC';
+ print ' ';
+ $sql = 'SELECT datep as dp, pf.amount,';
+ $sql .= ' c.libelle as paiement_type, p.num_paiement, p.rowid';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p';
+ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
+ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
+ $sql .= ' WHERE pf.fk_facturefourn = '.$fac->id;
+ $sql .= ' ORDER BY dp DESC';
- $result = $db->query($sql);
- if ($result)
- {
- $num = $db->num_rows($result);
- $i = 0; $totalpaye = 0;
- print '';
- print '';
- print ''.$langs->trans('Payments').' ';
- print ''.$langs->trans('Type').' ';
+ $result = $db->query($sql);
+ if ($result)
+ {
+ $num = $db->num_rows($result);
+ $i = 0; $totalpaye = 0;
+ print '';
+ print '';
+ print ''.$langs->trans('Payments').' ';
+ print ''.$langs->trans('Type').' ';
- if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
- {
- $tdsup=' colspan="2"';
- }
- print ''.$langs->trans('AmountTTC').' ';
+ if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
+ {
+ $tdsup=' colspan="2"';
+ }
+ print ''.$langs->trans('AmountTTC').' ';
- $var=True;
- while ($i < $num)
- {
- $objp = $db->fetch_object($result);
- $var=!$var;
- print '';
- print ''.img_object($langs->trans('ShowPayment'),'payment').' '.dol_print_date($db->jdate($objp->dp),'day')." \n";
- print ''.$objp->paiement_type.' '.$objp->num_paiement.' ';
- print ''.price($objp->amount).' '.$langs->trans('Currency'.$conf->monnaie).' ';
+ $var=True;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($result);
+ $var=!$var;
+ print ' ';
+ print ''.img_object($langs->trans('ShowPayment'),'payment').' '.dol_print_date($db->jdate($objp->dp),'day')." \n";
+ print ''.$objp->paiement_type.' '.$objp->num_paiement.' ';
+ print ''.price($objp->amount).' '.$langs->trans('Currency'.$conf->monnaie).' ';
- if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
- {
- print '';
- print '';
- print img_delete();
- print ' ';
- }
+ if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
+ {
+ print '';
+ print '';
+ print img_delete();
+ print ' ';
+ }
- print ' ';
- $totalpaye += $objp->amount;
- $i++;
- }
+ print '';
+ $totalpaye += $objp->amount;
+ $i++;
+ }
- if ($fac->paye == 0)
- {
- print ''.$langs->trans('AlreadyPaid').' : '.price($totalpaye).' '.$langs->trans('Currency'.$conf->monnaie).' ';
- print ''.$langs->trans("Billed").' : '.price($fac->total_ttc).' '.$langs->trans('Currency'.$conf->monnaie).' ';
+ if ($fac->paye == 0)
+ {
+ print ''.$langs->trans('AlreadyPaid').' : '.price($totalpaye).' '.$langs->trans('Currency'.$conf->monnaie).' ';
+ print ''.$langs->trans("Billed").' : '.price($fac->total_ttc).' '.$langs->trans('Currency'.$conf->monnaie).' ';
- $resteapayer = $fac->total_ttc - $totalpaye;
+ $resteapayer = $fac->total_ttc - $totalpaye;
- print ''.$langs->trans('RemainderToPay').' : ';
- print ''.price($resteapayer).' '.$langs->trans('Currency'.$conf->monnaie).' ';
- }
- print '
';
- $db->free($result);
- }
- else
- {
- dol_print_error($db);
- }
- print '';
+ print ' '.$langs->trans('RemainderToPay').' : ';
+ print ''.price($resteapayer).' '.$langs->trans('Currency'.$conf->monnaie).' ';
+ }
+ print '
';
+ $db->free($result);
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+ print ' ';
- print ' ';
+ print '';
- // Date
- print ''.$langs->trans('Date').' ';
- print dol_print_date($fac->datep,'daytext').' ';
+ // Date
+ print ''.$langs->trans('Date').' ';
+ print dol_print_date($fac->datep,'daytext').' ';
- // Due date
- print '';
- print ''.$langs->trans('DateEcheance').' ';
- print dol_print_date($fac->date_echeance,'daytext');
- if (($fac->paye == 0) && ($fac->statut > 0) && $fac->date_echeance && $fac->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)) print img_picto($langs->trans("Late"),"warning");
- print ' ';
+ // Due date
+ print '';
+ print ''.$langs->trans('DateEcheance').' ';
+ print dol_print_date($fac->date_echeance,'daytext');
+ if (($fac->paye == 0) && ($fac->statut > 0) && $fac->date_echeance && $fac->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)) print img_picto($langs->trans("Late"),"warning");
+ print ' ';
- // Status
- $alreadypaid=$fac->getSommePaiement();
- print ''.$langs->trans('Status').' '.$fac->getLibStatut(4,$alreadypaid).' ';
+ // Status
+ $alreadypaid=$fac->getSommePaiement();
+ print ''.$langs->trans('Status').' '.$fac->getLibStatut(4,$alreadypaid).' ';
- print ''.$langs->trans('AmountHT').' '.price($fac->total_ht).' '.$langs->trans('Currency'.$conf->monnaie).' ';
- print ''.$langs->trans('AmountVAT').' '.price($fac->total_tva).' '.$langs->trans('Currency'.$conf->monnaie).' ';
+ print ''.$langs->trans('AmountHT').' '.price($fac->total_ht).' '.$langs->trans('Currency'.$conf->monnaie).' ';
+ print ''.$langs->trans('AmountVAT').' '.price($fac->total_tva).' '.$langs->trans('Currency'.$conf->monnaie).' ';
- // Amount Local Taxes
- if ($mysoc->pays_code=='ES')
- {
- if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
- {
- print ''.$langs->transcountry("AmountLT1",$mysoc->pays_code).' ';
- print ''.price($propal->total_localtax1).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
- }
- if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
- {
- print ''.$langs->transcountry("AmountLT2",$mysoc->pays_code).' ';
- print ''.price($propal->total_localtax2).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
- }
- }
- print ''.$langs->trans('AmountTTC').' '.price($fac->total_ttc).' '.$langs->trans('Currency'.$conf->monnaie).' ';
+ // Amount Local Taxes
+ if ($mysoc->pays_code=='ES')
+ {
+ if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
+ {
+ print ''.$langs->transcountry("AmountLT1",$mysoc->pays_code).' ';
+ print ''.price($propal->total_localtax1).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+ }
+ if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
+ {
+ print ''.$langs->transcountry("AmountLT2",$mysoc->pays_code).' ';
+ print ''.price($propal->total_localtax2).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+ }
+ }
+ print ''.$langs->trans('AmountTTC').' '.price($fac->total_ttc).' '.$langs->trans('Currency'.$conf->monnaie).' ';
- // Project
- if ($conf->projet->enabled)
- {
- $langs->load('projects');
- print '';
- print '';
+ // Project
+ if ($conf->projet->enabled)
+ {
+ $langs->load('projects');
+ print ' ';
+ print '';
- print '';
+ print '';
- print ' ';
- if ($_GET['action'] == 'classer')
- {
- $html->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->fk_project,'projectid');
- }
- else
- {
- $html->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->fk_project,'none');
- }
- print ' ';
- print ' ';
- }
+ print '';
+ if ($_GET['action'] == 'classer')
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->fk_project,'projectid');
+ }
+ else
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->fk_project,'none');
+ }
+ print ' ';
+ print '';
+ }
- print '
';
+ print '
';
- /*
- * Lines
- */
- print ' ';
- print '';
- $var=1;
- for ($i = 0 ; $i < sizeof($fac->lines) ; $i++)
- {
- if ($i == 0)
- {
- print ''.$langs->trans('Label').' ';
- print ''.$langs->trans('VAT').' ';
- print ''.$langs->trans('PriceUHT').' ';
- print ''.$langs->trans('PriceUTTC').' ';
- print ''.$langs->trans('Qty').' ';
- print ''.$langs->trans('TotalHTShort').' ';
- print ''.$langs->trans('TotalTTCShort').' ';
- print ' ';
- print ' ';
- print ' ';
- }
+ /*
+ * Lines
+ */
+ print ' ';
+ print '';
+ $var=1;
+ for ($i = 0 ; $i < sizeof($fac->lines) ; $i++)
+ {
+ if ($i == 0)
+ {
+ print ''.$langs->trans('Label').' ';
+ print ''.$langs->trans('VAT').' ';
+ print ''.$langs->trans('PriceUHT').' ';
+ print ''.$langs->trans('PriceUTTC').' ';
+ print ''.$langs->trans('Qty').' ';
+ print ''.$langs->trans('TotalHTShort').' ';
+ print ''.$langs->trans('TotalTTCShort').' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ }
- // Show product and description
- $type=$fac->lines[$i]->product_type?$fac->lines[$i]->product_type:$fac->lines[$i]->fk_product_type;
- // Try to enhance type detection using date_start and date_end for free lines where type
- // was not saved.
- if (! empty($fac->lines[$i]->date_start)) $type=1;
- if (! empty($fac->lines[$i]->date_end)) $type=1;
+ // Show product and description
+ $type=$fac->lines[$i]->product_type?$fac->lines[$i]->product_type:$fac->lines[$i]->fk_product_type;
+ // Try to enhance type detection using date_start and date_end for free lines where type
+ // was not saved.
+ if (! empty($fac->lines[$i]->date_start)) $type=1;
+ if (! empty($fac->lines[$i]->date_end)) $type=1;
- $var=!$var;
+ $var=!$var;
- // Edit line
- if ($fac->statut == 0 && $_GET['action'] == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['ligne_id'] == $fac->lines[$i]->rowid)
- {
- print '';
- print ' ';
- print ' ';
- print '';
+ // Edit line
+ if ($fac->statut == 0 && $_GET['action'] == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['lineid'] == $fac->lines[$i]->rowid)
+ {
+ print 'id.'&etat=1&lineid='.$fac->lines[$i]->rowid.'" method="post">';
+ print ' ';
+ print ' ';
+ print '';
- // Show product and description
- print '';
- if (($conf->product->enabled || $conf->service->enabled) && $fac->lines[$i]->fk_product)
- {
- print ' ';
- $product_static=new ProductFournisseur($db);
- $product_static->fetch($fac->lines[$i]->fk_product);
- $text=$product_static->getNomUrl(1);
- $text.= ' - '.$product_static->libelle;
- print $text;
- print ' ';
- }
- else
- {
- print $html->select_type_of_lines($fac->lines[$i]->product_type,'type',1);
- if ($conf->product->enabled && $conf->service->enabled) print ' ';
- }
+ // Show product and description
+ print ' ';
+ if (($conf->product->enabled || $conf->service->enabled) && $fac->lines[$i]->fk_product)
+ {
+ print ' ';
+ $product_static=new ProductFournisseur($db);
+ $product_static->fetch($fac->lines[$i]->fk_product);
+ $text=$product_static->getNomUrl(1);
+ $text.= ' - '.$product_static->libelle;
+ print $text;
+ print ' ';
+ }
+ else
+ {
+ print $html->select_type_of_lines($fac->lines[$i]->product_type,'type',1);
+ if ($conf->product->enabled && $conf->service->enabled) print ' ';
+ }
- // Description - Editor wysiwyg
- require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
+ // Description - Editor wysiwyg
+ require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$nbrows=ROWS_2;
if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
- $doleditor=new DolEditor('label',$fac->lines[$i]->description,200,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
- $doleditor->Create();
- print ' ';
+ $doleditor=new DolEditor('label',$fac->lines[$i]->description,200,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
+ $doleditor->Create();
+ print '';
- // VAT
- print '';
- $html->select_tva('tauxtva',$fac->lines[$i]->tva_tx,$societe,$mysoc);
- print ' ';
+ // VAT
+ print '';
+ $html->select_tva('tauxtva',$fac->lines[$i]->tva_tx,$societe,$mysoc);
+ print ' ';
- // Unit price
- print ' ';
+ // Unit price
+ print ' ';
- print ' ';
+ print ' ';
- print ' ';
+ print ' ';
- print ' ';
+ print ' ';
- print ' ';
+ print ' ';
- print ' ';
- print ' ';
+ print ' ';
+ print ' ';
- print ' ';
- print ' ';
- }
- else // Affichage simple de la ligne
- {
- print ' ';
+ print ' ';
+ print ' ';
+ }
+ else // Affichage simple de la ligne
+ {
+ print '';
- // Show product and description
- print '';
- if ($fac->lines[$i]->fk_product)
- {
- print ' '; // ancre pour retourner sur la ligne
+ // Show product and description
+ print ' ';
+ if ($fac->lines[$i]->fk_product)
+ {
+ print ' '; // ancre pour retourner sur la ligne
- $product_static=new ProductFournisseur($db);
- $product_static->fetch($fac->lines[$i]->fk_product);
- $text=$product_static->getNomUrl(1);
- $text.= ' - '.$product_static->libelle;
- $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($fac->lines[$i]->description));
- print $html->textwithtooltip($text,$description,3,'','',$i);
+ $product_static=new ProductFournisseur($db);
+ $product_static->fetch($fac->lines[$i]->fk_product);
+ $text=$product_static->getNomUrl(1);
+ $text.= ' - '.$product_static->libelle;
+ $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($fac->lines[$i]->description));
+ print $html->textwithtooltip($text,$description,3,'','',$i);
- // Show range
- print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end);
+ // Show range
+ print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end);
- // Add description in form
- if ($conf->global->PRODUIT_DESC_IN_FORM) print ($fac->lines[$i]->description && $fac->lines[$i]->description!=$product_static->libelle)?' '.dol_htmlentitiesbr($fac->lines[$i]->description):'';
- }
+ // Add description in form
+ if ($conf->global->PRODUIT_DESC_IN_FORM) print ($fac->lines[$i]->description && $fac->lines[$i]->description!=$product_static->libelle)?' '.dol_htmlentitiesbr($fac->lines[$i]->description):'';
+ }
- // Description - Editor wysiwyg
- if (! $fac->lines[$i]->fk_product)
- {
- if ($type==1) $text = img_object($langs->trans('Service'),'service');
- else $text = img_object($langs->trans('Product'),'product');
- print $text.' '.nl2br($fac->lines[$i]->description);
+ // Description - Editor wysiwyg
+ if (! $fac->lines[$i]->fk_product)
+ {
+ if ($type==1) $text = img_object($langs->trans('Service'),'service');
+ else $text = img_object($langs->trans('Product'),'product');
+ print $text.' '.nl2br($fac->lines[$i]->description);
- // Show range
- print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end);
- }
- print ' ';
+ // Show range
+ print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end);
+ }
+ print '';
- // VAT
- print ''.vatrate($fac->lines[$i]->tva_tx).'% ';
+ // VAT
+ print ''.vatrate($fac->lines[$i]->tva_tx).'% ';
- // Unit price
- print ''.price($fac->lines[$i]->pu_ht,'MU').' ';
+ // Unit price
+ print ''.price($fac->lines[$i]->pu_ht,'MU').' ';
- print ''.($fac->lines[$i]->pu_ttc?price($fac->lines[$i]->pu_ttc,'MU'):' ').' ';
+ print ''.($fac->lines[$i]->pu_ttc?price($fac->lines[$i]->pu_ttc,'MU'):' ').' ';
- print ''.$fac->lines[$i]->qty.' ';
+ print ''.$fac->lines[$i]->qty.' ';
- print ''.price($fac->lines[$i]->total_ht).' ';
+ print ''.price($fac->lines[$i]->total_ht).' ';
- print ''.price($fac->lines[$i]->total_ttc).' ';
+ print ''.price($fac->lines[$i]->total_ttc).' ';
- print '';
- if ($fac->statut == 0) print ''.img_edit().' ';
- else print ' ';
- print ' ';
+ print '';
+ if ($fac->statut == 0) print ''.img_edit().' ';
+ else print ' ';
+ print ' ';
- print '';
- if ($fac->statut == 0) print ''.img_delete().' ';
- else print ' ';
- print ' ';
+ print '';
+ if ($fac->statut == 0) print ''.img_delete().' ';
+ else print ' ';
+ print ' ';
- print ' ';
- }
+ print '';
+ }
- }
+ }
- /*
- * Form to add new line
- */
+ /*
+ * Form to add new line
+ */
- if ($fac->statut == 0 && $_GET['action'] != 'mod_ligne')
- {
- print '';
- print '';
- print ' '; // ancre
- print $langs->trans('AddNewLine').' - '.$langs->trans("FreeZone").' ';
- print ''.$langs->trans('VAT').' ';
- print ''.$langs->trans('PriceUHT').' ';
- print ''.$langs->trans('PriceUTTC').' ';
- print ''.$langs->trans('Qty').' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
+ if ($fac->statut == 0 && $_GET['action'] != 'mod_ligne')
+ {
+ print '';
+ print '';
+ print ' '; // ancre
+ print $langs->trans('AddNewLine').' - '.$langs->trans("FreeZone").' ';
+ print ''.$langs->trans('VAT').' ';
+ print ''.$langs->trans('PriceUHT').' ';
+ print ''.$langs->trans('PriceUTTC').' ';
+ print ''.$langs->trans('Qty').' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
- // Add free products/services form
- print '';
- print ' ';
- print ' ';
- print ' ';
+ // Add free products/services form
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
- $var=true;
- print '';
- print '';
+ $var=true;
+ print ' ';
+ print '';
- $forceall=1; // For suppliers, we always show all types
- print $html->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,0,$forceall);
- if ($forceall || ($conf->product->enabled && $conf->service->enabled)
- || (empty($conf->product->enabled) && empty($conf->service->enabled))) print ' ';
+ $forceall=1; // For suppliers, we always show all types
+ print $html->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,0,$forceall);
+ if ($forceall || ($conf->product->enabled && $conf->service->enabled)
+ || (empty($conf->product->enabled) && empty($conf->service->enabled))) print ' ';
- // Editor wysiwyg
- require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
+ // Editor wysiwyg
+ require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$nbrows=ROWS_2;
if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
- $doleditor=new DolEditor('label',$_POST["label"],100,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
- $doleditor->Create();
+ $doleditor=new DolEditor('label',GETPOST("label"),100,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
+ $doleditor->Create();
- print ' ';
- print '';
- print $html->select_tva('tauxtva',$conf->defaulttx,$societe,$mysoc);
- print ' ';
- print '';
- print ' ';
- print ' ';
- print '';
- print ' ';
- print ' ';
- print '';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
+ print '';
+ print '';
+ print $html->select_tva('tauxtva',$conf->defaulttx,$societe,$mysoc);
+ print ' ';
+ print '';
+ print ' ';
+ print ' ';
+ print '';
+ print ' ';
+ print ' ';
+ print '';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print '';
- // Ajout de produits/services predefinis
- if ($conf->product->enabled || $conf->service->enabled)
- {
- print '';
- print '';
- print $langs->trans("AddNewLine").' - ';
- if ($conf->service->enabled)
- {
- print $langs->trans('RecordedProductsAndServices');
- }
- else
- {
- print $langs->trans('RecordedProducts');
- }
- print ' ';
- print ''.$langs->trans('Qty').' ';
- print ' ';
- print ' ';
- print ' ';
+ // Ajout de produits/services predefinis
+ if ($conf->product->enabled || $conf->service->enabled)
+ {
+ print '';
+ print '';
+ print $langs->trans("AddNewLine").' - ';
+ if ($conf->service->enabled)
+ {
+ print $langs->trans('RecordedProductsAndServices');
+ }
+ else
+ {
+ print $langs->trans('RecordedProducts');
+ }
+ print ' ';
+ print ''.$langs->trans('Qty').' ';
+ print ' ';
+ print ' ';
+ print ' ';
- print '';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- $var=! $var;
- print '';
- print '';
- $html->select_produits_fournisseurs($fac->socid,'','idprodfournprice','',$filtre);
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- }
- }
+ print '';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ $var=! $var;
+ print '';
+ print '';
+ $html->select_produits_fournisseurs($fac->socid,'','idprodfournprice','',$filtre);
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ }
+ }
- print '
';
+ print '
';
- print '';
- }
+ print '';
+ }
- if ($_GET['action'] != 'presend')
- {
+ if ($_GET['action'] != 'presend')
+ {
- /*
- * Boutons actions
- */
-
- print '';
-
- if ($_GET['action'] != 'edit')
- {
- print '';
- print ' '; // ancre
-
- /*
- * Documents generes
- */
-
- $facfournref=dol_sanitizeFileName($fac->ref);
- $file=$conf->fournisseur->dir_output.'/facture/'. $facfournref . '/' . $facfournref . '.pdf';
- $relativepath = $facfournref.'/'.$facfournref.'.pdf';
- $filedir = $conf->fournisseur->dir_output . '/facture/' . $facfournref;
- $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id;
- $genallowed=$user->rights->fournisseur->facture->creer;
- $delallowed=$user->rights->fournisseur->facture->supprimer;
-
- $somethingshown=$formfile->show_documents('facture_fournisseur',$facfournref,$filedir,$urlsource,$genallowed,$delallowed,$facture->modelpdf);
-
- print ' ';
- print ' ';
-
- // List of actions on element
- /*
- include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
- $formactions=new FormActions($db);
- $somethingshown=$formactions->showactions($fac,'invoice_supplier',$socid);
- */
-
- print '
';
- }
- }
- /*
- * Show mail form
- */
- if ($_GET['action'] == 'presend')
- {
- $ref = dol_sanitizeFileName($fac->ref);
- $file = $conf->fournisseur->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
-
- print ' ';
- print_titre($langs->trans('SendBillByMail'));
+ /*
+ * Boutons actions
+ */
- // Cree l'objet formulaire mail
- include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- $formmail->fromtype = 'user';
- $formmail->fromid = $user->id;
- $formmail->fromname = $user->getFullName($langs);
- $formmail->frommail = $user->email;
- $formmail->withfrom=1;
- $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"];
- $formmail->withtosocid=$soc->id;
- $formmail->withtocc=1;
- $formmail->withtoccsocid=0;
- $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
- $formmail->withtocccsocid=0;
- $formmail->withtopic=$langs->trans('SendBillRef','__FACREF__');
- $formmail->withfile=2;
- $formmail->withbody=1;
- $formmail->withdeliveryreceipt=1;
- $formmail->withcancel=1;
- // Tableau des substitutions
- $formmail->substit['__FACREF__']=$fac->ref;
- // Tableau des parametres complementaires
- $formmail->param['action']='send';
- $formmail->param['models']='supplier_facture_send';
- $formmail->param['facid']=$fac->id;
- $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?facid='.$fac->id;
+ print '';
- // Init list of files
- if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
- {
- $formmail->clear_attached_files();
- $formmail->add_attached_files($file,$ref.'.pdf','application/pdf');
- }
+ // Reopen a standard paid invoice
+ if (($fac->type == 0 || $fac->type == 1) && ($fac->statut == 2 || $fac->statut == 3)) // A paid invoice (partially or completely)
+ {
+ if (! $facidnext && $fac->close_code != 'replaced') // Not replaced by another invoice
+ {
+ print '
'.$langs->trans('ReOpen').' ';
+ }
+ else
+ {
+ print '
'.$langs->trans('ReOpen').' ';
+ }
+ }
- // Show form
- $formmail->show_form();
+ //Modify
+ if ($_GET['action'] != 'edit' && $fac->statut <= 1 && $fac->getSommePaiement() <= 0 && $user->rights->fournisseur->facture->creer)
+ {
+ print '
'.$langs->trans('Modify').' ';
+ }
- print '
';
- }
- }
+ // Send by mail
+ if (($fac->statut == 1 || $fac->statut == 2) && $user->rights->facture->envoyer)
+ {
+ print '
'.$langs->trans('SendByMail').' ';
+ }
+
+
+ //Make payments
+ if ($_GET['action'] != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
+ {
+ print '
'.$langs->trans('DoPayment').' ';
+ }
+
+ //Classify paid
+ if ($_GET['action'] != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
+ {
+ print '
id.'&action=paid"';
+ print '>'.$langs->trans('ClassifyPaid').' ';
+
+ //print '
'.$langs->trans('ClassifyPaid').' ';
+ }
+
+ //Validate
+ if ($_GET['action'] != 'edit' && $fac->statut == 0)
+ {
+ if (sizeof($fac->lines))
+ {
+ if ($user->rights->fournisseur->facture->valider)
+ {
+ print '
id.'&action=valid"';
+ print '>'.$langs->trans('Validate').' ';
+ }
+ else
+ {
+ print '
'.$langs->trans('Validate').' ';
+ }
+ }
+ }
+
+ //Clone
+ if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->creer)
+ {
+ print '
'.$langs->trans('ToClone').' ';
+ }
+
+ //Delete
+ if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->supprimer)
+ {
+ print '
'.$langs->trans('Delete').' ';
+ }
+ print '
';
+
+ if ($_GET['action'] != 'edit')
+ {
+ print '';
+ print ' '; // ancre
+
+ /*
+ * Documents generes
+ */
+
+ $facfournref=dol_sanitizeFileName($fac->ref);
+ $file=$conf->fournisseur->dir_output.'/facture/'. $facfournref . '/' . $facfournref . '.pdf';
+ $relativepath = $facfournref.'/'.$facfournref.'.pdf';
+ $filedir = $conf->fournisseur->dir_output . '/facture/' . $facfournref;
+ $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id;
+ $genallowed=$user->rights->fournisseur->facture->creer;
+ $delallowed=$user->rights->fournisseur->facture->supprimer;
+
+ $somethingshown=$formfile->show_documents('facture_fournisseur',$facfournref,$filedir,$urlsource,$genallowed,$delallowed,$facture->modelpdf);
+
+ print ' ';
+ print ' ';
+
+ // List of actions on element
+ /*
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
+ $formactions=new FormActions($db);
+ $somethingshown=$formactions->showactions($fac,'invoice_supplier',$socid);
+ */
+
+ print '
';
+ }
+ }
+ /*
+ * Show mail form
+ */
+ if ($_GET['action'] == 'presend')
+ {
+ $ref = dol_sanitizeFileName($fac->ref);
+ $file = $conf->fournisseur->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
+
+ print ' ';
+ print_titre($langs->trans('SendBillByMail'));
+
+ // Cree l'objet formulaire mail
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
+ $formmail = new FormMail($db);
+ $formmail->fromtype = 'user';
+ $formmail->fromid = $user->id;
+ $formmail->fromname = $user->getFullName($langs);
+ $formmail->frommail = $user->email;
+ $formmail->withfrom=1;
+ $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"];
+ $formmail->withtosocid=$soc->id;
+ $formmail->withtocc=1;
+ $formmail->withtoccsocid=0;
+ $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
+ $formmail->withtocccsocid=0;
+ $formmail->withtopic=$langs->trans('SendBillRef','__FACREF__');
+ $formmail->withfile=2;
+ $formmail->withbody=1;
+ $formmail->withdeliveryreceipt=1;
+ $formmail->withcancel=1;
+ // Tableau des substitutions
+ $formmail->substit['__FACREF__']=$fac->ref;
+ // Tableau des parametres complementaires
+ $formmail->param['action']='send';
+ $formmail->param['models']='supplier_facture_send';
+ $formmail->param['facid']=$fac->id;
+ $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?facid='.$fac->id;
+
+ // Init list of files
+ if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
+ {
+ $formmail->clear_attached_files();
+ $formmail->add_attached_files($file,$ref.'.pdf','application/pdf');
+ }
+
+ // Show form
+ $formmail->show_form();
+
+ print ' ';
+ }
+ }
}
$db->close();