Qual: Uniformize look of supplier invoice with customer invoice

This commit is contained in:
eldy 2011-10-01 21:55:40 +02:00
parent 4d4be413af
commit 79546fa072
7 changed files with 962 additions and 1026 deletions

View File

@ -79,9 +79,9 @@ $hookmanager=new HookManager($db);
$hookmanager->callHooks(array('invoicecard')); $hookmanager->callHooks(array('invoicecard'));
/******************************************************************************/ /*
/* Actions */ * Actions
/******************************************************************************/ */
$parameters=array('socid'=>$socid); $parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
@ -239,7 +239,7 @@ if ($action == 'setmode')
{ {
$object->fetch($id); $object->fetch($id);
$result=$object->mode_reglement($_POST['mode_reglement_id']); $result=$object->mode_reglement($_POST['mode_reglement_id']);
if ($result < 0) dol_print_error($object->db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
if ($action == 'setinvoicedate') if ($action == 'setinvoicedate')
@ -248,7 +248,7 @@ if ($action == 'setinvoicedate')
$object->date=dol_mktime(12,0,0,$_POST['invoicedatemonth'],$_POST['invoicedateday'],$_POST['invoicedateyear']); $object->date=dol_mktime(12,0,0,$_POST['invoicedatemonth'],$_POST['invoicedateday'],$_POST['invoicedateyear']);
if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement=$object->date; if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement=$object->date;
$result=$object->update($user); $result=$object->update($user);
if ($result < 0) dol_print_error($object->db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
if ($action == 'setpaymentterm') if ($action == 'setpaymentterm')
@ -256,14 +256,14 @@ if ($action == 'setpaymentterm')
$object->fetch($id); $object->fetch($id);
$date_lim_reglement=dol_mktime(12,0,0,$_POST['paymenttermmonth'],$_POST['paymenttermday'],$_POST['paymenttermyear']); $date_lim_reglement=dol_mktime(12,0,0,$_POST['paymenttermmonth'],$_POST['paymenttermday'],$_POST['paymenttermyear']);
$result=$object->cond_reglement($object->cond_reglement_id,$date_lim_reglement); $result=$object->cond_reglement($object->cond_reglement_id,$date_lim_reglement);
if ($result < 0) dol_print_error($object->db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
if ($action == 'setconditions') if ($action == 'setconditions')
{ {
$object->fetch($id); $object->fetch($id);
$result=$object->cond_reglement($_POST['cond_reglement_id']); $result=$object->cond_reglement($_POST['cond_reglement_id']);
if ($result < 0) dol_print_error($object->db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
if ($action == 'setremisepercent' && $user->rights->facture->creer) if ($action == 'setremisepercent' && $user->rights->facture->creer)

View File

@ -97,14 +97,14 @@ class Form
* @param string $preselected Preselected value for parameter * @param string $preselected Preselected value for parameter
* @param string $paramkey Key of parameter (unique if there is several parameter to show) * @param string $paramkey Key of parameter (unique if there is several parameter to show)
* @param boolean $perm Permission to allow button to edit parameter * @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data ('string' by default, 'email', 'text', ...) * @param string $typeofdata Type of data ('string' by default, 'email', 'text', 'day', ...)
* @param string $editvalue Use this value instead $preselected * @param string $editvalue Use this value instead $preselected
* @return string HTML edit field * @return string HTML edit field
* TODO no GET or POST in class file, use a param * TODO no GET or POST in class file, use a param
*/ */
function editfieldval($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='') function editfieldval($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='')
{ {
global $langs; global $langs,$db;
$ret=''; $ret='';
if (GETPOST('action') == 'edit'.$htmlname) if (GETPOST('action') == 'edit'.$htmlname)
{ {
@ -123,14 +123,20 @@ class Form
{ {
$ret.='<textarea name="'.$htmlname.'">'.($editvalue?$editvalue:$preselected).'</textarea>'; $ret.='<textarea name="'.$htmlname.'">'.($editvalue?$editvalue:$preselected).'</textarea>';
} }
else if ($typeofdata == 'day')
{
$html=new Form($db);
$ret.=$html->form_date($_SERVER['PHP_SELF'].($paramkey?'?'.$paramkey.'='.$paramvalue:''),$preselected,$htmlname);
}
$ret.='</td>'; $ret.='</td>';
$ret.='<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>'; if ($typeofdata != 'day') $ret.='<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
$ret.='</tr></table>'."\n"; $ret.='</tr></table>'."\n";
$ret.='</form>'."\n"; $ret.='</form>'."\n";
} }
else else
{ {
if ($typeofdata == 'email') $ret.=dol_print_email($preselected,0,0,0,0,1); if ($typeofdata == 'email') $ret.=dol_print_email($preselected,0,0,0,0,1);
if ($typeofdata == 'day') $ret.=dol_print_date($preselected,'day');
else $ret.=$preselected; else $ret.=$preselected;
} }
return $ret; return $ret;

View File

@ -432,7 +432,7 @@ class FormFile
if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && $modulepart != 'unpaid') if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && $modulepart != 'unpaid')
{ {
$langs->load("errors"); $langs->load("errors");
$out.= ' '.img_warning($langs->trans("WarningNoDocumentModelActivated")); $out.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
} }
$out.= '</td>'; $out.= '</td>';

View File

@ -57,10 +57,10 @@ class FactureFournisseur extends Facture
var $author; var $author;
var $libelle; var $libelle;
var $datec; var $datec; // Creation date
var $tms; var $tms; // Last update date
var $date; var $date; // Invoice date
var $date_echeance; var $date_echeance; // Max payment date
var $amount; var $amount;
var $remise; var $remise;
var $tva; var $tva;
@ -184,7 +184,8 @@ class FactureFournisseur extends Facture
{ {
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det'); $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
$this->updateline($idligne, $this->updateline(
$idligne,
$this->lines[$i]->description, $this->lines[$i]->description,
$this->lines[$i]->pu_ht, $this->lines[$i]->pu_ht,
$this->lines[$i]->tva_tx, $this->lines[$i]->tva_tx,
@ -246,10 +247,12 @@ class FactureFournisseur extends Facture
/** /**
* Load object in memory from database * Load object in memory from database
* @param id id object *
* @param int $id Id supplier invoice
* @param string $ref Ref supplier invoice
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function fetch($id) function fetch($id='',$ref='')
{ {
global $langs; global $langs;
$sql = "SELECT"; $sql = "SELECT";
@ -287,7 +290,9 @@ class FactureFournisseur extends Facture
$sql.= " t.import_key,"; $sql.= " t.import_key,";
$sql.= ' s.nom as socnom, s.rowid as socid'; $sql.= ' s.nom as socnom, s.rowid as socid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as t,'.MAIN_DB_PREFIX.'societe as s'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as t,'.MAIN_DB_PREFIX.'societe as s';
$sql.= ' WHERE t.rowid='.$id.' AND t.fk_soc = s.rowid'; if ($id) $sql.= " WHERE t.rowid=".$id;
if ($ref) $sql.= " WHERE t.rowid='".$this->db->escape($ref)."'"; // ref is id (facnumber is supplier ref)
$sql.= ' AND t.fk_soc = s.rowid';
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@ -369,8 +374,9 @@ class FactureFournisseur extends Facture
/** /**
* \brief Load this->lines * Load this->lines
* \return int 1 si ok, < 0 si erreur *
* @return int 1 si ok, < 0 si erreur
*/ */
function fetch_lines() function fetch_lines()
{ {
@ -433,10 +439,11 @@ class FactureFournisseur extends Facture
/** /**
* \brief Update database * Update database
* \param user User that modify *
* \param notrigger 0=launch triggers after, 1=disable triggers * @param User $user User that modify
* \return int <0 if KO, >0 if OK * @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/ */
function update($user=0, $notrigger=0) function update($user=0, $notrigger=0)
{ {
@ -486,7 +493,7 @@ class FactureFournisseur extends Facture
$sql.= " fk_soc=".(isset($this->fk_soc)?$this->fk_soc:"null").","; $sql.= " fk_soc=".(isset($this->fk_soc)?$this->fk_soc:"null").",";
$sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
$sql.= " datef=".(dol_strlen($this->date)!=0 ? "'".$this->db->idate($this->date)."'" : 'null').","; $sql.= " datef=".(dol_strlen($this->date)!=0 ? "'".$this->db->idate($this->date)."'" : 'null').",";
$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; if (dol_strlen($this->tms) != 0) $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
$sql.= " libelle=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").","; $sql.= " libelle=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
$sql.= " paye=".(isset($this->paye)?$this->paye:"null").","; $sql.= " paye=".(isset($this->paye)?$this->paye:"null").",";
$sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; $sql.= " amount=".(isset($this->amount)?$this->amount:"null").",";

View File

@ -41,15 +41,16 @@ $langs->load('bills');
$langs->load('suppliers'); $langs->load('suppliers');
$langs->load('companies'); $langs->load('companies');
$mesg='';
$facid=GETPOST("facid"); $facid=GETPOST("facid");
$action=GETPOST("action");
// Security check // Security check
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'fournisseur', $facid, 'facture_fourn', 'facture'); $result = restrictedArea($user, 'fournisseur', $facid, 'facture_fourn', 'facture');
$html = new Form($db); $object=new FactureFournisseur($db);
$mesg='';
$action=GETPOST("action");
/* /*
@ -57,7 +58,7 @@ $action=GETPOST("action");
*/ */
// Action clone object // Action clone object
if ($_REQUEST["action"] == 'confirm_clone' && $_REQUEST['confirm'] == 'yes') if ($action == 'confirm_clone' && $_REQUEST['confirm'] == 'yes')
{ {
if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"])) if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
{ {
@ -65,8 +66,7 @@ if ($_REQUEST["action"] == 'confirm_clone' && $_REQUEST['confirm'] == 'yes')
} }
else else
{ {
$object=new FactureFournisseur($db); $result=$object->createFromClone($facid);
$result=$object->createFromClone($_REQUEST['facid']);
if ($result > 0) if ($result > 0)
{ {
header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result); header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result);
@ -82,24 +82,22 @@ if ($_REQUEST["action"] == 'confirm_clone' && $_REQUEST['confirm'] == 'yes')
} }
} }
if ($_REQUEST['action'] == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->facture->valider) if ($action == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->facture->valider)
{ {
$facturefourn=new FactureFournisseur($db); $object->fetch($facid);
$facturefourn->fetch($_GET['facid']); $result = $object->validate($user);
$result = $facturefourn->validate($user);
if ($result < 0) if ($result < 0)
{ {
$mesg='<div class="error">'.$facturefourn->error.'</div>'; $mesg='<div class="error">'.$object->error.'</div>';
} }
} }
if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes') if ($action == 'confirm_delete' && $_REQUEST['confirm'] == 'yes')
{ {
if ($user->rights->fournisseur->facture->supprimer ) if ($user->rights->fournisseur->facture->supprimer )
{ {
$facturefourn = new FactureFournisseur($db); $object->fetch($facid);
$factfournid = $_GET['facid']; $result=$object->delete($facid);
$result=$facturefourn->delete($factfournid);
if ($result > 0) if ($result > 0)
{ {
Header('Location: index.php'); Header('Location: index.php');
@ -107,54 +105,67 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes')
} }
else else
{ {
$mesg='<div class="error">'.$facturefourn->error.'</div>'; $mesg='<div class="error">'.$object->error.'</div>';
} }
} }
} }
if ($_REQUEST['action'] == 'confirm_deleteproductline' && $_REQUEST['confirm'] == 'yes') if ($action == 'confirm_deleteproductline' && $_REQUEST['confirm'] == 'yes')
{ {
if ($user->rights->fournisseur->facture->creer) if ($user->rights->fournisseur->facture->creer)
{ {
$facturefourn = new FactureFournisseur($db); $object->fetch($facid);
$facturefourn->fetch($facid); $object->deleteline($_REQUEST['lineid']);
$facturefourn->deleteline($_REQUEST['lineid']);
$_GET['action'] = ''; $_GET['action'] = '';
} }
} }
if ($_REQUEST['action'] == 'confirm_paid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->facture->creer) if ($action == 'confirm_paid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->facture->creer)
{ {
$facturefourn=new FactureFournisseur($db); $object->fetch($facid);
$facturefourn->fetch($_GET['facid']); $result=$object->set_paid($user);
$result=$facturefourn->set_paid($user);
} }
// Set supplier ref // Set supplier ref
if (($_POST['action'] == 'setref_supplier' || $_POST['action'] == 'set_ref_supplier') && $user->rights->fournisseur->facture->creer) if (($action == 'setref_supplier' || $action == 'set_ref_supplier') && $user->rights->fournisseur->facture->creer)
{ {
$facturefourn = new FactureFournisseur($db); $object->fetch($facid);
$facturefourn->fetch($facid); $result=$object->set_ref_supplier($user, $_POST['ref_supplier']);
$result=$facturefourn->set_ref_supplier($user, $_POST['ref_supplier']);
$_GET['facid']=$facid; $_GET['facid']=$facid;
} }
// Set supplier ref // Set supplier ref
if (($_POST['action'] == 'setlabel') && $user->rights->fournisseur->facture->creer) if ($action == 'setlabel' && $user->rights->fournisseur->facture->creer)
{ {
$facturefourn = new FactureFournisseur($db); $object->fetch($facid);
$facturefourn->fetch($facid); $object->label=$_POST['label'];
$facturefourn->label=$_POST['label']; $result=$object->update($user);
$result=$facturefourn->update($user);
if ($result < 0) dol_print_error($db); if ($result < 0) dol_print_error($db);
$_GET['facid']=$facid; $_GET['facid']=$facid;
} }
if($_GET['action'] == 'deletepaiement') if ($action == 'setdate' && $user->rights->fournisseur->facture->creer)
{ {
$facfou = new FactureFournisseur($db); $object->fetch($facid);
$facfou->fetch($_GET['facid']); $object->date=dol_mktime(12,0,0,$_POST['datemonth'],$_POST['dateday'],$_POST['dateyear']);
if ($facfou->statut == 1 && $facfou->paye == 0 && $user->societe_id == 0) if ($object->date_echeance < $object->date) $object->date_echeance=$object->date;
$result=$object->update($user);
if ($result < 0) dol_print_error($db,$object->error);
}
if ($action == 'setdate_echeance' && $user->rights->fournisseur->facture->creer)
{
$object->fetch($facid);
$object->date_echeance=dol_mktime(12,0,0,$_POST['date_echeancemonth'],$_POST['date_echeanceday'],$_POST['date_echeanceyear']);
if ($object->date_echeance < $object->date) $object->date_echeance=$object->date;
$result=$object->update($user);
if ($result < 0) dol_print_error($db,$object->error);
}
// Delete payment
if($action == 'deletepaiement')
{
$object->fetch($_GET['facid']);
if ($object->statut == 1 && $object->paye == 0 && $user->societe_id == 0)
{ {
$paiementfourn = new PaiementFourn($db); $paiementfourn = new PaiementFourn($db);
$paiementfourn->fetch($_GET['paiement_id']); $paiementfourn->fetch($_GET['paiement_id']);
@ -162,7 +173,7 @@ if($_GET['action'] == 'deletepaiement')
} }
} }
if ($_POST['action'] == 'update' && ! $_POST['cancel']) if ($action == 'update' && ! $_POST['cancel'])
{ {
$error=0; $error=0;
@ -194,7 +205,7 @@ if ($_POST['action'] == 'update' && ! $_POST['cancel'])
/* /*
* Action creation * Action creation
*/ */
if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) if ($action == 'add' && $user->rights->fournisseur->facture->creer)
{ {
$error=0; $error=0;
@ -204,14 +215,14 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
if ($datefacture == '') if ($datefacture == '')
{ {
$mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('DateInvoice')).'</div>'; $mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('DateInvoice')).'</div>';
$_GET['action']='create'; $action='create';
$_GET['socid']=$_POST['socid']; $_GET['socid']=$_POST['socid'];
$error++; $error++;
} }
if (! GETPOST('facnumber')) if (! GETPOST('facnumber'))
{ {
$mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'</div>'; $mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'</div>';
$_GET['action']='create'; $action='create';
$_GET['socid']=$_POST['socid']; $_GET['socid']=$_POST['socid'];
$error++; $error++;
} }
@ -221,14 +232,12 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
$db->begin(); $db->begin();
// Creation facture // Creation facture
$facfou = new FactureFournisseur($db); $object->ref = $_POST['facnumber'];
$object->socid = $_POST['socid'];
$facfou->ref = $_POST['facnumber']; $object->libelle = $_POST['libelle'];
$facfou->socid = $_POST['socid']; $object->date = $datefacture;
$facfou->libelle = $_POST['libelle']; $object->date_echeance = $datedue;
$facfou->date = $datefacture; $object->note_public = $_POST['note'];
$facfou->date_echeance = $datedue;
$facfou->note_public = $_POST['note'];
// If creation from another object of another module // If creation from another object of another module
if ($_POST['origin'] && $_POST['originid']) if ($_POST['origin'] && $_POST['originid'])
@ -247,10 +256,10 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
if ($element == 'contract') { $element = $subelement = 'contrat'; } if ($element == 'contract') { $element = $subelement = 'contrat'; }
if ($element == 'order_supplier') { $element = 'fourn'; $subelement = 'fournisseur.commande'; } if ($element == 'order_supplier') { $element = 'fourn'; $subelement = 'fournisseur.commande'; }
$facfou->origin = $_POST['origin']; $object->origin = $_POST['origin'];
$facfou->origin_id = $_POST['originid']; $object->origin_id = $_POST['originid'];
$facid = $facfou->create($user); $facid = $object->create($user);
// Add lines // Add lines
if ($facid > 0) if ($facid > 0)
@ -281,7 +290,7 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
$result = $facfou->addline( $result = $object->addline(
$desc, $desc,
$lines[$i]->subprice, $lines[$i]->subprice,
$lines[$i]->tva_tx, $lines[$i]->tva_tx,
@ -318,7 +327,7 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
// If some invoice's lines already known // If some invoice's lines already known
else else
{ {
$facid = $facfou->create($user); $facid = $object->create($user);
if ($facid < 0) if ($facid < 0)
{ {
$error++; $error++;
@ -349,7 +358,7 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
$product=new Product($db); $product=new Product($db);
$product->fetch($_POST['idprod'.$i]); $product->fetch($_POST['idprod'.$i]);
$ret=$facfou->addline($label, $amount, $tauxtva, $product->localtax1_tx, $product->localtax2_tx, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base); $ret=$object->addline($label, $amount, $tauxtva, $product->localtax1_tx, $product->localtax2_tx, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base);
if ($ret < 0) $error++; if ($ret < 0) $error++;
} }
} }
@ -360,8 +369,8 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
{ {
$langs->load("errors"); $langs->load("errors");
$db->rollback(); $db->rollback();
$mesg='<div class="error">'.$langs->trans($facfou->error).'</div>'; $mesg='<div class="error">'.$langs->trans($object->error).'</div>';
$_GET['action']='create'; $action='create';
$_GET['socid']=$_POST['socid']; $_GET['socid']=$_POST['socid'];
} }
else else
@ -373,21 +382,19 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
} }
} }
if ($_GET['action'] == 'del_ligne') if ($action == 'del_ligne')
{ {
$facfou = new FactureFournisseur($db); $object->fetch($_GET['facid']);
$facfou->fetch($_GET['facid']); $object->deleteline($_GET['lineid']);
$facfou->deleteline($_GET['lineid']); $action = 'edit';
$_GET['action'] = 'edit';
} }
// Modification d'une ligne // Modification d'une ligne
if ($_REQUEST['action'] == 'update_line') if ($action == 'update_line')
{ {
if ($_REQUEST['etat'] == '1' && ! $_REQUEST['cancel']) // si on valide la modification if ($_REQUEST['etat'] == '1' && ! $_REQUEST['cancel']) // si on valide la modification
{ {
$facfou = new FactureFournisseur($db); $object->fetch($_GET['facid']);
$facfou->fetch($_GET['facid']);
if ($_POST['puht']) if ($_POST['puht'])
{ {
@ -413,10 +420,10 @@ if ($_REQUEST['action'] == 'update_line')
} }
else else
{ {
if ($facfou->socid) if ($object->socid)
{ {
$societe=new Societe($db); $societe=new Societe($db);
$societe->fetch($facfou->socid); $societe->fetch($object->socid);
} }
$label = $_POST['label']; $label = $_POST['label'];
$type = $_POST["type"]?$_POST["type"]:0; $type = $_POST["type"]?$_POST["type"]:0;
@ -424,7 +431,7 @@ if ($_REQUEST['action'] == 'update_line')
$localtax2tx= get_localtax($_POST['tauxtva'], 2, $societe); $localtax2tx= get_localtax($_POST['tauxtva'], 2, $societe);
} }
$result=$facfou->updateline($_GET['lineid'], $label, $pu, $_POST['tauxtva'], $localtax1tx, $localtax2tx, $_POST['qty'], $_POST['idprod'], $price_base_type, 0, $type); $result=$object->updateline($_GET['lineid'], $label, $pu, $_POST['tauxtva'], $localtax1tx, $localtax2tx, $_POST['qty'], $_POST['idprod'], $price_base_type, 0, $type);
if ($result >= 0) if ($result >= 0)
{ {
unset($_POST['label']); unset($_POST['label']);
@ -432,25 +439,23 @@ if ($_REQUEST['action'] == 'update_line')
} }
} }
if ($_GET['action'] == 'addline') if ($action == 'addline')
{ {
$facfou = new FactureFournisseur($db); $ret=$object->fetch($_GET['facid']);
$ret=$facfou->fetch($_GET['facid']);
if ($ret < 0) if ($ret < 0)
{ {
dol_print_error($db,$facfou->error); dol_print_error($db,$object->error);
exit; exit;
} }
if ($facfou->socid) if ($object->socid)
{ {
$societe=new Societe($db); $societe=new Societe($db);
$societe->fetch($facfou->socid); $societe->fetch($object->socid);
} }
if ($_POST['idprodfournprice']) // > 0 or -1 if ($_POST['idprodfournprice']) // > 0 or -1
{ {
$product = new ProductFournisseur($db);
$idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']); $idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']);
if ($idprod > 0) if ($idprod > 0)
{ {
@ -469,7 +474,7 @@ if ($_GET['action'] == 'addline')
$type = $product->type; $type = $product->type;
$result=$facfou->addline($label, $product->fourn_pu, $tvatx, $localtax2tx, $localtax2tx, $_POST['qty'], $idprod); $result=$object->addline($label, $product->fourn_pu, $tvatx, $localtax2tx, $localtax2tx, $_POST['qty'], $idprod);
} }
if ($idprod == -1) if ($idprod == -1)
{ {
@ -497,14 +502,14 @@ if ($_GET['action'] == 'addline')
$price_base_type = 'HT'; $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) //$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, $localtax1tx, $localtax2tx, $_POST['qty'], 0, 0, $datestart, $dateend, 0, 0, $price_base_type, $type); $result=$object->addline($_POST['label'], $ht, $tauxtva, $localtax1tx, $localtax2tx, $_POST['qty'], 0, 0, $datestart, $dateend, 0, 0, $price_base_type, $type);
} }
else else
{ {
$ttc = price2num($_POST['amountttc']); $ttc = price2num($_POST['amountttc']);
$ht = $ttc / (1 + ($tauxtva / 100)); $ht = $ttc / (1 + ($tauxtva / 100));
$price_base_type = 'HT'; $price_base_type = 'HT';
$result=$facfou->addline($_POST['label'], $ht, $tauxtva,$localtax1tx, $localtax2tx, $_POST['qty'], 0, 0, $datestart, $dateend, 0, 0, $price_base_type, $type); $result=$object->addline($_POST['label'], $ht, $tauxtva,$localtax1tx, $localtax2tx, $_POST['qty'], 0, 0, $datestart, $dateend, 0, 0, $price_base_type, $type);
} }
} }
} }
@ -534,30 +539,28 @@ if ($_GET['action'] == 'addline')
} }
else if (empty($mesg)) else if (empty($mesg))
{ {
$mesg='<div class="error">'.$facfou->error.'</div>'; $mesg='<div class="error">'.$object->error.'</div>';
} }
$_GET['action'] = ''; $action = '';
} }
if ($_POST['action'] == 'classin') if ($action == 'classin')
{ {
$facture = new FactureFournisseur($db); $object->fetch($_GET['facid']);
$facture->fetch($_GET['facid']); $result=$object->setProject($_POST['projectid']);
$result=$facture->setProject($_POST['projectid']);
} }
// Repasse la facture en mode brouillon // Repasse la facture en mode brouillon
if ($_GET['action'] == 'edit' && $user->rights->fournisseur->facture->creer) if ($action == 'edit' && $user->rights->fournisseur->facture->creer)
{ {
$fac = new FactureFournisseur($db); $object->fetch($_GET['facid']);
$fac->fetch($_GET['facid']);
// On verifie si la facture a des paiements // On verifie si la facture a des paiements
$sql = 'SELECT pf.amount'; $sql = 'SELECT pf.amount';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf'; $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf';
$sql.= ' WHERE pf.fk_facturefourn = '.$fac->id; $sql.= ' WHERE pf.fk_facturefourn = '.$object->id;
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
@ -573,15 +576,15 @@ if ($_GET['action'] == 'edit' && $user->rights->fournisseur->facture->creer)
} }
} }
$resteapayer = $fac->total_ttc - $totalpaye; $resteapayer = $object->total_ttc - $totalpaye;
// On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
//$ventilExportCompta = $fac->getVentilExportCompta(); //$ventilExportCompta = $object->getVentilExportCompta();
// On verifie si aucun paiement n'a ete effectue // On verifie si aucun paiement n'a ete effectue
if ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0) if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
{ {
$fac->set_draft($user); $object->set_draft($user);
$outputlangs = $langs; $outputlangs = $langs;
if (! empty($_REQUEST['lang_id'])) if (! empty($_REQUEST['lang_id']))
@ -589,18 +592,17 @@ if ($_GET['action'] == 'edit' && $user->rights->fournisseur->facture->creer)
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
//supplier_invoice_pdf_create($db, $fac->id, $fac->modelpdf, $outputlangs); //supplier_invoice_pdf_create($db, $object->id, $object->modelpdf, $outputlangs);
} }
} }
if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->facture->creer) if ($action == 'reopen' && $user->rights->fournisseur->facture->creer)
{ {
$fac = new FactureFournisseur($db); $result = $object->fetch($_GET['facid']);
$result = $fac->fetch($_GET['facid']); if ($object->statut == 2
if ($fac->statut == 2 || ($object->statut == 3 && $object->close_code != 'replaced'))
|| ($fac->statut == 3 && $fac->close_code != 'replaced'))
{ {
$result = $fac->set_unpaid($user); $result = $object->set_unpaid($user);
if ($result > 0) if ($result > 0)
{ {
Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']); Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']);
@ -608,18 +610,11 @@ if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->facture->creer)
} }
else else
{ {
$mesg='<div class="error">'.$fac->error.'</div>'; $mesg='<div class="error">'.$object->error.'</div>';
} }
} }
} }
/*********************************************************************
*
* Mail Actions
*
**********************************************************************/
/* /*
* Add file in email form * Add file in email form
*/ */
@ -633,8 +628,7 @@ if ($_POST['addfile'])
$mesg=dol_add_file_process($upload_dir_tmp,0,0); $mesg=dol_add_file_process($upload_dir_tmp,0,0);
$_GET["action"]='presend'; $action='presend';
$_POST["action"]='presend';
} }
/* /*
@ -650,23 +644,21 @@ if (! empty($_POST['removedfile']))
$mesg=dol_remove_file_process($_POST['removedfile'],0); $mesg=dol_remove_file_process($_POST['removedfile'],0);
$_GET["action"]='presend'; $action='presend';
$_POST["action"]='presend';
} }
/* /*
* Send mail * Send mail
*/ */
if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
{ {
$langs->load('mails'); $langs->load('mails');
$facturefourn=new FactureFournisseur($db); $object->fetch($_GET['facid']);
$facturefourn->fetch($_GET['facid']); $result=$object->fetch_thirdparty();
$result=$facturefourn->fetch_thirdparty();
if ($result > 0) if ($result > 0)
{ {
$ref = dol_sanitizeFileName($facturefourn->ref); $ref = dol_sanitizeFileName($object->ref);
$file = $conf->fournisseur->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; $file = $conf->fournisseur->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (is_readable($file)) if (is_readable($file))
@ -682,12 +674,12 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
// Recipient was provided from combo list // Recipient was provided from combo list
if ($_POST['receiver'] == 'thirdparty') // Id of third party if ($_POST['receiver'] == 'thirdparty') // Id of third party
{ {
$sendto = $facturefourn->client->email; $sendto = $object->client->email;
$sendtoid = 0; $sendtoid = 0;
} }
else // Id du contact else // Id du contact
{ {
$sendto = $facturefourn->client->contact_get_property($_POST['receiver'],'email'); $sendto = $object->client->contact_get_property($_POST['receiver'],'email');
$sendtoid = $_POST['receiver']; $sendtoid = $_POST['receiver'];
} }
} }
@ -702,10 +694,10 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
$sendtocc = $_POST['sendtocc']; $sendtocc = $_POST['sendtocc'];
$deliveryreceipt = $_POST['deliveryreceipt']; $deliveryreceipt = $_POST['deliveryreceipt'];
if ($_POST['action'] == 'send') if ($action == 'send')
{ {
if (dol_strlen($_POST['subject'])) $subject=$_POST['subject']; if (dol_strlen($_POST['subject'])) $subject=$_POST['subject'];
else $subject = $langs->transnoentities('CustomerOrder').' '.$facturefourn->ref; else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
$actiontypecode='AC_SUP_ORD'; $actiontypecode='AC_SUP_ORD';
$actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
if ($message) if ($message)
@ -743,17 +735,17 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
$error=0; $error=0;
// Initialisation donnees // Initialisation donnees
$facturefourn->sendtoid = $sendtoid; $object->sendtoid = $sendtoid;
$facturefourn->actiontypecode = $actiontypecode; $object->actiontypecode = $actiontypecode;
$facturefourn->actionmsg = $actionmsg; $object->actionmsg = $actionmsg;
$facturefourn->actionmsg2 = $actionmsg2; $object->actionmsg2 = $actionmsg2;
$facturefourn->fk_element = $facturefourn->id; $object->fk_element = $object->id;
$facturefourn->elementtype = $facturefourn->element; $object->elementtype = $object->element;
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($db); $interface=new Interfaces($db);
$result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$facturefourn,$user,$langs,$conf); $result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$object,$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
@ -765,7 +757,7 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
{ {
// Redirect here // Redirect here
// This avoid sending mail twice if going out and then back to page // This avoid sending mail twice if going out and then back to page
Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facturefourn->id.'&mesg='.urlencode($mesg)); Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&mesg='.urlencode($mesg));
exit; exit;
} }
} }
@ -808,26 +800,20 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
dol_syslog('Unable to read data from the invoice. The invoice file has perhaps not been generated.'); dol_syslog('Unable to read data from the invoice. The invoice file has perhaps not been generated.');
} }
//$_GET['action'] = 'presend'; //$action = 'presend';
} }
/* /*
* Build document * Build document
*/ */
if ($_REQUEST['action'] == 'builddoc') if ($action == 'builddoc')
{ {
/*
* Generation de la facture
* definit dans /includes/modules/supplier_invoice/modules_facturefournisseur.php
*/
// Save modele used // Save modele used
$facture=new FactureFournisseur($db); $object->fetch($_REQUEST['facid']);
$facture->fetch($_REQUEST['facid']);
if ($_REQUEST['model']) if ($_REQUEST['model'])
{ {
$facture->setDocModel($user, $_REQUEST['model']); $object->setDocModel($user, $_REQUEST['model']);
} }
$outputlangs = $langs; $outputlangs = $langs;
@ -836,7 +822,7 @@ if ($_REQUEST['action'] == 'builddoc')
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
$result=supplier_invoice_pdf_create($db, $facture,$facture->modelpdf,$outputlangs); $result=supplier_invoice_pdf_create($db, $object,$object->modelpdf,$outputlangs);
if ($result <= 0) if ($result <= 0)
{ {
dol_print_error($db,$result); dol_print_error($db,$result);
@ -844,7 +830,7 @@ if ($_REQUEST['action'] == 'builddoc')
} }
else else
{ {
Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facture->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit; exit;
} }
} }
@ -853,9 +839,8 @@ if ($_REQUEST['action'] == 'builddoc')
if ($action == 'remove_file') if ($action == 'remove_file')
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$facture = new FactureFournisseur($db);
if ($facture->fetch($id)) if ($object->fetch($id))
{ {
$upload_dir = $conf->fournisseur->facture->dir_output . "/"; $upload_dir = $conf->fournisseur->facture->dir_output . "/";
$file = $upload_dir . '/' . $_GET['file']; $file = $upload_dir . '/' . $_GET['file'];
@ -869,17 +854,17 @@ if ($action=='remove_file')
* View * View
*/ */
llxHeader('','',''); $html = new Form($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
llxHeader('','','');
// Mode creation // Mode creation
if ($_GET['action'] == 'create') if ($action == 'create')
{ {
print_fiche_titre($langs->trans('NewBill')); print_fiche_titre($langs->trans('NewBill'));
if ($mesg) { print $mesg.'<br>'; } dol_htmloutput_mesg($mesg);
$societe=''; $societe='';
if ($_GET['socid']) if ($_GET['socid'])
@ -1058,7 +1043,7 @@ if ($_GET['action'] == 'create')
print '</td></tr>'; print '</td></tr>';
// Due date // Due date
print '<tr><td>'.$langs->trans('DateEcheance').'</td><td>'; print '<tr><td>'.$langs->trans('DateMaxPayment').'</td><td>';
$html->select_date($datedue,'ech','','','',"add",1,1); $html->select_date($datedue,'ech','','','',"add",1,1);
print '</td></tr>'; print '</td></tr>';
@ -1149,68 +1134,6 @@ else
$societe = new Fournisseur($db); $societe = new Fournisseur($db);
$societe->fetch($fac->socid); $societe->fetch($fac->socid);
if ($_GET['action'] == 'edit')
{
print_fiche_titre($langs->trans('SupplierInvoice'));
print '<form name="update" action="fiche.php?facid='.$fac->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<table class="border" width="100%">';
print '<tr><td class="fieldrequired">'.$langs->trans('Company').'</td>';
print '<td>'.$societe->getNomUrl(1).'</td>';
print '<td width="50%" valign="top">'.$langs->trans('NotePublic').'</td>';
print '</tr>';
// Ref
print '<tr><td valign="top">'.$langs->trans('Ref').'</td><td valign="top">';
print $fac->ref.'</td>';
$rownb=10;
print '<td rowspan="'.$rownb.'" valign="top">';
print '<textarea name="note" wrap="soft" cols="60" rows="'.$rownb.'">';
print $fac->note;
print '</textarea></td></tr>';
// Ref supplier
print '<tr><td valign="top" class="fieldrequired">'.$langs->trans('RefSupplier').'</td><td valign="top">';
print '<input name="facnumber" type="text" value="'.$fac->ref_supplier.'"></td>';
print '</tr>';
// Label
print '<tr><td valign="top">'.$langs->trans('Label').'</td><td>';
print '<input size="30" name="libelle" type="text" value="'.$fac->libelle.'"></td></tr>';
// Date invoice
print '<tr><td class="fieldrequired">'.$langs->trans('DateInvoice').'</td><td nowrap="nowrap">';
$html->select_date($fac->datep,'','','','',"update",1,1);
print '</td></tr>';
// Due date
print '<tr><td>'.$langs->trans('DateEcheance').'</td><td nowrap="nowrap">';
$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>';
print '<tr><td>'.$langs->trans('AmountHT').'</td><td nowrap="nowrap"><b>'.price($fac->total_ht).'</b></td></tr>';
print '<tr><td>'.$langs->trans('AmountVAT').'</td><td nowrap="nowrap">'.price($fac->total_tva).'</td></tr>';
print '<tr><td>'.$langs->trans('AmountTTC').'</td><td nowrap="nowrap">'.price($fac->total_ttc).'</td></tr>';
print '<tr><td>'.$langs->trans('Status').'</td><td>'.$fac->getLibStatut(4).'</td></tr>';
print '<tr><td colspan="2" align="center">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans('Save').'">';
print ' &nbsp; &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
print '</td></tr>';
print '</table>';
print '</form>';
print '</table>';
}
else
{
/* /*
* View card * View card
*/ */
@ -1218,17 +1141,17 @@ else
$titre=$langs->trans('SupplierInvoice'); $titre=$langs->trans('SupplierInvoice');
dol_fiche_head($head, 'card', $titre, 0, 'bill'); dol_fiche_head($head, 'card', $titre, 0, 'bill');
if ($mesg) { print $mesg.'<br>'; } dol_htmloutput_mesg($mesg);
// Confirmation de la suppression d'une ligne produit // Confirmation de la suppression d'une ligne produit
if ($_GET['action'] == 'confirm_delete_line') if ($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); $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 '<br>'; if ($ret == 'html') print '<br>';
} }
// Clone confirmation // Clone confirmation
if ($_GET["action"] == 'clone') if ($action == 'clone')
{ {
// Create an array for form // Create an array for form
$formquestion=array( $formquestion=array(
@ -1241,14 +1164,14 @@ else
} }
// Confirmation de la validation // Confirmation de la validation
if ($_GET['action'] == 'valid') if ($action == 'valid')
{ {
$ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('ValidateBill'), $langs->trans('ConfirmValidateBill', $fac->ref), 'confirm_valid', '', 0, 1); $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 '<br>'; if ($ret == 'html') print '<br>';
} }
// Confirmation set paid // Confirmation set paid
if ($_GET['action'] == 'paid') if ($action == 'paid')
{ {
$ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $fac->ref), 'confirm_paid', '', 0, 1); $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 '<br>'; if ($ret == 'html') print '<br>';
@ -1257,7 +1180,7 @@ else
/* /*
* Confirmation de la suppression de la facture fournisseur * Confirmation de la suppression de la facture fournisseur
*/ */
if ($_GET['action'] == 'delete') if ($action == 'delete')
{ {
$ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1); $ret=$html->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
@ -1361,12 +1284,9 @@ else
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Payments').'</td>'; print '<td>'.$langs->trans('Payments').'</td>';
print '<td>'.$langs->trans('Type').'</td>'; print '<td>'.$langs->trans('Type').'</td>';
print '<td align="right">'.$langs->trans('Amount').'</td>';
if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) print '<td width="18">&nbsp;</td>';
{ print '</tr>';
$tdsup=' colspan="2"';
}
print '<td align="right">'.$langs->trans('AmountTTC').'</td><td'.$tdsup.'>&nbsp;</td></tr>';
$var=True; $var=True;
while ($i < $num) while ($i < $num)
@ -1376,16 +1296,15 @@ else
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td nowrap><a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans('ShowPayment'),'payment').' '.dol_print_date($db->jdate($objp->dp),'day')."</a></td>\n"; print '<td nowrap><a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans('ShowPayment'),'payment').' '.dol_print_date($db->jdate($objp->dp),'day')."</a></td>\n";
print '<td>'.$objp->paiement_type.' '.$objp->num_paiement.'</td>'; print '<td>'.$objp->paiement_type.' '.$objp->num_paiement.'</td>';
print '<td align="right">'.price($objp->amount).'</td><td>&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td>'; print '<td align="right">'.price($objp->amount).'</td>';
print '<td align="center">';
if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
{ {
print '<td align="center">';
print '<a href="fiche.php?facid='.$fac->id.'&amp;action=deletepaiement&amp;paiement_id='.$objp->rowid.'">'; print '<a href="fiche.php?facid='.$fac->id.'&amp;action=deletepaiement&amp;paiement_id='.$objp->rowid.'">';
print img_delete(); print img_delete();
print '</a></td>'; print '</a>';
} }
print '</td>';
print '</tr>'; print '</tr>';
$totalpaye += $objp->amount; $totalpaye += $objp->amount;
$i++; $i++;
@ -1393,13 +1312,13 @@ else
if ($fac->paye == 0) if ($fac->paye == 0)
{ {
print '<tr><td colspan="2" align="right">'.$langs->trans('AlreadyPaid').' :</td><td align="right"><b>'.price($totalpaye).'</b></td><td>&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>'; print '<tr><td colspan="2" align="right">'.$langs->trans('AlreadyPaid').' :</td><td align="right"><b>'.price($totalpaye).'</b></td></tr>';
print '<tr><td colspan="2" align="right">'.$langs->trans("Billed").' :</td><td align="right" style="border: 1px solid;">'.price($fac->total_ttc).'</td><td>&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>'; print '<tr><td colspan="2" align="right">'.$langs->trans("Billed").' :</td><td align="right" style="border: 1px solid;">'.price($fac->total_ttc).'</td></tr>';
$resteapayer = $fac->total_ttc - $totalpaye; $resteapayer = $fac->total_ttc - $totalpaye;
print '<tr><td colspan="2" align="right">'.$langs->trans('RemainderToPay').' :</td>'; print '<tr><td colspan="2" align="right">'.$langs->trans('RemainderToPay').' :</td>';
print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($resteapayer).'</b></td><td>&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>'; print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($resteapayer).'</b></td></tr>';
} }
print '</table>'; print '</table>';
$db->free($result); $db->free($result);
@ -1410,19 +1329,17 @@ else
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Date // Date
print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3" nowrap="nowrap">'; print '<tr><td>'.$html->editfieldkey("Date",'date',$fac->datep,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0)).'</td><td colspan="3">';
print dol_print_date($fac->datep,'daytext').'</td></tr>'; print $html->editfieldval("Date",'date',$fac->datep,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0),'day');
print '</td>';
// Due date // Due date
print '<tr>'; print '<tr><td>'.$html->editfieldkey("DateMaxPayment",'date_echeance',$fac->date_echeance,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0)).'</td><td colspan="3">';
print '<td>'.$langs->trans('DateEcheance').'</td><td colspan="3">'; print $html->editfieldval("DateMaxPayment",'date_echeance',$fac->date_echeance,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0),'day');
print dol_print_date($fac->date_echeance,'daytext'); print '</td>';
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 '</td></tr>';
// Status // Status
$alreadypaid=$fac->getSommePaiement(); $alreadypaid=$fac->getSommePaiement();
@ -1459,7 +1376,7 @@ else
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project'); print $langs->trans('Project');
print '</td>'; print '</td>';
if ($_GET['action'] != 'classify') if ($action != 'classify')
{ {
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;facid='.$fac->id.'">'; print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;facid='.$fac->id.'">';
print img_edit($langs->trans('SetProject'),1); print img_edit($langs->trans('SetProject'),1);
@ -1468,7 +1385,7 @@ else
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="3">'; print '</td><td colspan="3">';
if ($_GET['action'] == 'classify') if ($action == 'classify')
{ {
$html->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->fk_project,'projectid'); $html->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->fk_project,'projectid');
} }
@ -1516,7 +1433,7 @@ else
$var=!$var; $var=!$var;
// Edit line // Edit line
if ($fac->statut == 0 && $_GET['action'] == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['lineid'] == $fac->lines[$i]->rowid) if ($fac->statut == 0 && $action == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['lineid'] == $fac->lines[$i]->rowid)
{ {
print '<form action="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;etat=1&amp;lineid='.$fac->lines[$i]->rowid.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;etat=1&amp;lineid='.$fac->lines[$i]->rowid.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -1640,7 +1557,7 @@ else
* Form to add new line * Form to add new line
*/ */
if ($fac->statut == 0 && $_GET['action'] != 'mod_ligne') if ($fac->statut == 0 && $action != 'mod_ligne')
{ {
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'; print '<td>';
@ -1738,9 +1655,8 @@ else
print '</table>'; print '</table>';
print '</div>'; print '</div>';
}
if ($_GET['action'] != 'presend') if ($action != 'presend')
{ {
/* /*
@ -1762,12 +1678,6 @@ else
} }
} }
//Modify
if ($_GET['action'] != 'edit' && $fac->statut <= 1 && $fac->getSommePaiement() <= 0 && $user->rights->fournisseur->facture->creer)
{
print '<a class="butAction" href="fiche.php?facid='.$fac->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
}
// Send by mail // Send by mail
if (($fac->statut == 1 || $fac->statut == 2)) if (($fac->statut == 1 || $fac->statut == 2))
{ {
@ -1780,13 +1690,13 @@ else
//Make payments //Make payments
if ($_GET['action'] != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) if ($action != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
{ {
print '<a class="butAction" href="paiement.php?facid='.$fac->id.'&amp;action=create">'.$langs->trans('DoPayment').'</a>'; print '<a class="butAction" href="paiement.php?facid='.$fac->id.'&amp;action=create">'.$langs->trans('DoPayment').'</a>';
} }
//Classify paid //Classify paid
if ($_GET['action'] != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) if ($action != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
{ {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=paid"'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=paid"';
print '>'.$langs->trans('ClassifyPaid').'</a>'; print '>'.$langs->trans('ClassifyPaid').'</a>';
@ -1795,7 +1705,7 @@ else
} }
//Validate //Validate
if ($_GET['action'] != 'edit' && $fac->statut == 0) if ($action != 'edit' && $fac->statut == 0)
{ {
if (count($fac->lines)) if (count($fac->lines))
{ {
@ -1813,19 +1723,19 @@ else
} }
//Clone //Clone
if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->creer) if ($action != 'edit' && $user->rights->fournisseur->facture->creer)
{ {
print '<a class="butAction" href="fiche.php?facid='.$fac->id.'&amp;action=clone&amp;socid='.$fac->socid.'">'.$langs->trans('ToClone').'</a>'; print '<a class="butAction" href="fiche.php?facid='.$fac->id.'&amp;action=clone&amp;socid='.$fac->socid.'">'.$langs->trans('ToClone').'</a>';
} }
//Delete //Delete
if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->supprimer) if ($action != 'edit' && $user->rights->fournisseur->facture->supprimer)
{ {
print '<a class="butActionDelete" href="fiche.php?facid='.$fac->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'; print '<a class="butActionDelete" href="fiche.php?facid='.$fac->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
} }
print '</div>'; print '</div>';
if ($_GET['action'] != 'edit') if ($action != 'edit')
{ {
print '<table width="100%"><tr><td width="50%" valign="top">'; print '<table width="100%"><tr><td width="50%" valign="top">';
print '<a name="builddoc"></a>'; // ancre print '<a name="builddoc"></a>'; // ancre
@ -1865,7 +1775,7 @@ else
/* /*
* Show mail form * Show mail form
*/ */
if ($_GET['action'] == 'presend') if ($action == 'presend')
{ {
$ref = dol_sanitizeFileName($fac->ref); $ref = dol_sanitizeFileName($fac->ref);
$file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($fac->id,2).$ref.'.pdf'; $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($fac->id,2).$ref.'.pdf';

View File

@ -19,9 +19,16 @@
/** /**
* \file htdocs/lib/fourn.lib.php * \file htdocs/lib/fourn.lib.php
* \brief Ensemble de fonctions de base pour le module fournisseur * \brief Functions used by supplier invoice module
* \ingroup supplier
*/ */
/**
* Initialize the array of tabs for supplier invoice
*
* @param Facture $object Invoice object
* @return array Array of head tabs
*/
function facturefourn_prepare_head($object) function facturefourn_prepare_head($object)
{ {
global $langs, $conf; global $langs, $conf;
@ -29,7 +36,7 @@ function facturefourn_prepare_head($object)
$head = array(); $head = array();
$head[$h][0] = DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$object->id;
$head[$h][1] = $langs->trans('Card'); $head[$h][1] = $langs->trans('CardBill');
$head[$h][2] = 'card'; $head[$h][2] = 'card';
$h++; $h++;

View File

@ -18,10 +18,16 @@
/** /**
* \file htdocs/lib/invoice.lib.php * \file htdocs/lib/invoice.lib.php
* \brief Ensemble de fonctions de base pour le module factures * \brief Functions used by invoice module
* \ingroup invoice * \ingroup invoice
*/ */
/**
* Initialize the array of tabs for customer invoice
*
* @param Facture $object Invoice object
* @return array Array of head tabs
*/
function facture_prepare_head($object) function facture_prepare_head($object)
{ {
global $langs, $conf; global $langs, $conf;