From 79546fa072d4603663a11c3869246a64cc2579f0 Mon Sep 17 00:00:00 2001 From: eldy Date: Sat, 1 Oct 2011 21:55:40 +0200 Subject: [PATCH] Qual: Uniformize look of supplier invoice with customer invoice --- htdocs/compta/facture.php | 14 +- htdocs/core/class/html.form.class.php | 46 +- htdocs/core/class/html.formfile.class.php | 2 +- .../fourn/class/fournisseur.facture.class.php | 59 +- htdocs/fourn/facture/fiche.php | 1848 ++++++++--------- htdocs/lib/fourn.lib.php | 11 +- htdocs/lib/invoice.lib.php | 8 +- 7 files changed, 962 insertions(+), 1026 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index da3f0c5adb8..f86d78c14b2 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -79,9 +79,9 @@ $hookmanager=new HookManager($db); $hookmanager->callHooks(array('invoicecard')); -/******************************************************************************/ -/* Actions */ -/******************************************************************************/ +/* + * Actions + */ $parameters=array('socid'=>$socid); $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); $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') @@ -248,7 +248,7 @@ if ($action == 'setinvoicedate') $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; $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') @@ -256,14 +256,14 @@ if ($action == 'setpaymentterm') $object->fetch($id); $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); - if ($result < 0) dol_print_error($object->db,$object->error); + if ($result < 0) dol_print_error($db,$object->error); } if ($action == 'setconditions') { $object->fetch($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) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 3ea6ccb3d79..4a861d0eb3a 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -97,14 +97,14 @@ class Form * @param string $preselected Preselected value for parameter * @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 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 * @return string HTML edit field * TODO no GET or POST in class file, use a param */ function editfieldval($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='') { - global $langs; + global $langs,$db; $ret=''; if (GETPOST('action') == 'edit'.$htmlname) { @@ -123,14 +123,20 @@ class Form { $ret.=''; } + else if ($typeofdata == 'day') + { + $html=new Form($db); + $ret.=$html->form_date($_SERVER['PHP_SELF'].($paramkey?'?'.$paramkey.'='.$paramvalue:''),$preselected,$htmlname); + } $ret.=''; - $ret.=''; + if ($typeofdata != 'day') $ret.=''; $ret.=''."\n"; $ret.=''."\n"; } else { 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; } return $ret; @@ -238,7 +244,7 @@ class Form /** * Return combo list of activated countries, into language of user - * + * * @param selected Id or Code or Label of preselected country * @param htmlname Name of html select object * @param htmloption Options html on select object @@ -250,7 +256,7 @@ class Form /** * Return combo list of activated countries, into language of user - * + * * @param selected Id or Code or Label of preselected country * @param htmlname Name of html select object * @param htmloption Options html on select object @@ -320,7 +326,7 @@ class Form /** * Retourne la liste des types de comptes financiers - * + * * @param selected Type pre-selectionne * @param htmlname Nom champ formulaire */ @@ -356,7 +362,7 @@ class Form /** * Return list of social contributions. * Use mysoc->pays_id or mysoc->pays_code so they must be defined. - * + * * @param selected Preselected type * @param htmlname Name of field in form * @param useempty Set to 1 if we want an empty value @@ -426,7 +432,7 @@ class Form /** * Return list of types of lines (product or service) * Example: 0=product, 1=service, 9=other (for external module) - * + * * @param selected Preselected type * @param htmlname Name of field in html form * @param showempty Add an empty field @@ -517,7 +523,7 @@ class Form /** * Output html form to select a third party - * + * * @param selected Preselected type * @param htmlname Name of field in form * @param filter Optionnal filters criteras @@ -532,7 +538,7 @@ class Form /** * Output html form to select a third party - * + * * @param selected Preselected type * @param htmlname Name of field in form * @param filter Optionnal filters criteras @@ -608,7 +614,7 @@ class Form /** * Return HTML combo list of absolute discounts - * + * * @param selected Id remise fixe pre-selectionnee * @param htmlname Nom champ formulaire * @param filter Criteres optionnels de filtre @@ -674,7 +680,7 @@ class Form /** * Return list of all contacts (for a third party or all) - * + * * @param socid Id ot third party or 0 for all * @param selected Id contact pre-selectionne * @param htmlname Name of HTML field ('none' for a not editable field) @@ -900,7 +906,7 @@ class Form /** * Return list of products for customer in Ajax if Ajax activated or go to select_produits_do - * + * * @param selected Preselected products * @param htmlname Name of HTML seletc field (must be unique in page) * @param filtertype Filter on product type (''=nofilter, 0=product, 1=service) @@ -1425,7 +1431,7 @@ class Form /** * Return list of delivery address - * + * * @param string $selected Id contact pre-selectionn * @param int $socid Id of company * @param string $htmlname Name of HTML field @@ -1477,7 +1483,7 @@ class Form /** * Charge dans cache la liste des conditions de paiements possibles - * + * * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko */ function load_cache_conditions_paiements() @@ -1516,7 +1522,7 @@ class Form /** * Charge dans cache la liste des délais de livraison possibles - * + * * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko */ function load_cache_availability() @@ -1555,7 +1561,7 @@ class Form /** * Retourne la liste des types de delais de livraison possibles - * + * * @param selected Id du type de delais pre-selectionne * @param htmlname Nom de la zone select * @param filtertype To add a filter @@ -1588,7 +1594,7 @@ class Form /** * Load into cache cache_demand_reason, array of input reasons - * + * * @return int Nb of lines loaded, 0 if already loaded, <0 if ko */ function load_cache_demand_reason() @@ -1632,7 +1638,7 @@ class Form /** * Return list of events that triggered an object creation - * + * * @param selected Id du type d'origine pre-selectionne * @param htmlname Nom de la zone select * @param exclude To exclude a code value (Example: SRC_PROP) @@ -1667,7 +1673,7 @@ class Form /** * Charge dans cache la liste des types de paiements possibles - * + * * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko */ function load_cache_types_paiements() diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 54a4f7f2bb0..4d842d78c6d 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -432,7 +432,7 @@ class FormFile if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && $modulepart != 'unpaid') { $langs->load("errors"); - $out.= ' '.img_warning($langs->trans("WarningNoDocumentModelActivated")); + $out.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated")); } $out.= ''; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 1f529dcedc4..0c8e7e8324b 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -57,10 +57,10 @@ class FactureFournisseur extends Facture var $author; var $libelle; - var $datec; - var $tms; - var $date; - var $date_echeance; + var $datec; // Creation date + var $tms; // Last update date + var $date; // Invoice date + var $date_echeance; // Max payment date var $amount; var $remise; var $tva; @@ -184,17 +184,18 @@ class FactureFournisseur extends Facture { $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det'); - $this->updateline($idligne, - $this->lines[$i]->description, - $this->lines[$i]->pu_ht, - $this->lines[$i]->tva_tx, - $this->lines[$i]->localtax1_tx, - $this->lines[$i]->localtax2_tx, - $this->lines[$i]->qty, - $this->lines[$i]->fk_product, - 'HT', - $this->lines[$i]->info_bits, - $this->lines[$i]->product_type + $this->updateline( + $idligne, + $this->lines[$i]->description, + $this->lines[$i]->pu_ht, + $this->lines[$i]->tva_tx, + $this->lines[$i]->localtax1_tx, + $this->lines[$i]->localtax2_tx, + $this->lines[$i]->qty, + $this->lines[$i]->fk_product, + 'HT', + $this->lines[$i]->info_bits, + $this->lines[$i]->product_type ); } } @@ -246,10 +247,12 @@ class FactureFournisseur extends Facture /** * Load object in memory from database - * @param id id object - * @return int <0 if KO, >0 if OK + * + * @param int $id Id supplier invoice + * @param string $ref Ref supplier invoice + * @return int <0 if KO, >0 if OK */ - function fetch($id) + function fetch($id='',$ref='') { global $langs; $sql = "SELECT"; @@ -287,7 +290,9 @@ class FactureFournisseur extends Facture $sql.= " t.import_key,"; $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.= ' 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); $resql=$this->db->query($sql); @@ -369,8 +374,9 @@ class FactureFournisseur extends Facture /** - * \brief Load this->lines - * \return int 1 si ok, < 0 si erreur + * Load this->lines + * + * @return int 1 si ok, < 0 si erreur */ function fetch_lines() { @@ -433,10 +439,11 @@ class FactureFournisseur extends Facture /** - * \brief Update database - * \param user User that modify - * \param notrigger 0=launch triggers after, 1=disable triggers - * \return int <0 if KO, >0 if OK + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK */ 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.= " 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.= " 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.= " paye=".(isset($this->paye)?$this->paye:"null").","; $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 85d1aef932f..99688ccb13e 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -41,15 +41,16 @@ $langs->load('bills'); $langs->load('suppliers'); $langs->load('companies'); -$facid = GETPOST("facid"); +$mesg=''; +$facid=GETPOST("facid"); +$action=GETPOST("action"); // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'fournisseur', $facid, 'facture_fourn', 'facture'); -$html = new Form($db); -$mesg=''; -$action=GETPOST("action"); +$object=new FactureFournisseur($db); + /* @@ -57,7 +58,7 @@ $action=GETPOST("action"); */ // 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"])) { @@ -65,8 +66,7 @@ if ($_REQUEST["action"] == 'confirm_clone' && $_REQUEST['confirm'] == 'yes') } else { - $object=new FactureFournisseur($db); - $result=$object->createFromClone($_REQUEST['facid']); + $result=$object->createFromClone($facid); if ($result > 0) { 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); - $facturefourn->fetch($_GET['facid']); - $result = $facturefourn->validate($user); + $object->fetch($facid); + $result = $object->validate($user); if ($result < 0) { - $mesg='
'.$facturefourn->error.'
'; + $mesg='
'.$object->error.'
'; } } -if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes') +if ($action == 'confirm_delete' && $_REQUEST['confirm'] == 'yes') { if ($user->rights->fournisseur->facture->supprimer ) { - $facturefourn = new FactureFournisseur($db); - $factfournid = $_GET['facid']; - $result=$facturefourn->delete($factfournid); + $object->fetch($facid); + $result=$object->delete($facid); if ($result > 0) { Header('Location: index.php'); @@ -107,54 +105,67 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes') } else { - $mesg='
'.$facturefourn->error.'
'; + $mesg='
'.$object->error.'
'; } } } -if ($_REQUEST['action'] == 'confirm_deleteproductline' && $_REQUEST['confirm'] == 'yes') +if ($action == 'confirm_deleteproductline' && $_REQUEST['confirm'] == 'yes') { if ($user->rights->fournisseur->facture->creer) { - $facturefourn = new FactureFournisseur($db); - $facturefourn->fetch($facid); - $facturefourn->deleteline($_REQUEST['lineid']); + $object->fetch($facid); + $object->deleteline($_REQUEST['lineid']); $_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); - $facturefourn->fetch($_GET['facid']); - $result=$facturefourn->set_paid($user); + $object->fetch($facid); + $result=$object->set_paid($user); } // 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); - $facturefourn->fetch($facid); - $result=$facturefourn->set_ref_supplier($user, $_POST['ref_supplier']); + $object->fetch($facid); + $result=$object->set_ref_supplier($user, $_POST['ref_supplier']); $_GET['facid']=$facid; } // Set supplier ref -if (($_POST['action'] == 'setlabel') && $user->rights->fournisseur->facture->creer) +if ($action == 'setlabel' && $user->rights->fournisseur->facture->creer) { - $facturefourn = new FactureFournisseur($db); - $facturefourn->fetch($facid); - $facturefourn->label=$_POST['label']; - $result=$facturefourn->update($user); + $object->fetch($facid); + $object->label=$_POST['label']; + $result=$object->update($user); if ($result < 0) dol_print_error($db); $_GET['facid']=$facid; } -if($_GET['action'] == 'deletepaiement') +if ($action == 'setdate' && $user->rights->fournisseur->facture->creer) { - $facfou = new FactureFournisseur($db); - $facfou->fetch($_GET['facid']); - if ($facfou->statut == 1 && $facfou->paye == 0 && $user->societe_id == 0) + $object->fetch($facid); + $object->date=dol_mktime(12,0,0,$_POST['datemonth'],$_POST['dateday'],$_POST['dateyear']); + 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->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; @@ -194,24 +205,24 @@ if ($_POST['action'] == 'update' && ! $_POST['cancel']) /* * Action creation */ -if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) +if ($action == 'add' && $user->rights->fournisseur->facture->creer) { - $error=0; + $error=0; - $datefacture=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); + $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'; + $action='create'; $_GET['socid']=$_POST['socid']; $error++; } if (! GETPOST('facnumber')) { $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'
'; - $_GET['action']='create'; + $action='create'; $_GET['socid']=$_POST['socid']; $error++; } @@ -221,104 +232,102 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) $db->begin(); // 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']; + $object->ref = $_POST['facnumber']; + $object->socid = $_POST['socid']; + $object->libelle = $_POST['libelle']; + $object->date = $datefacture; + $object->date_echeance = $datedue; + $object->note_public = $_POST['note']; // If creation from another object of another module - if ($_POST['origin'] && $_POST['originid']) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = $_POST['origin']; - /*if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) - { - $element = $regs[1]; - $subelement = $regs[2]; - }*/ + if ($_POST['origin'] && $_POST['originid']) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = $_POST['origin']; + /*if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + }*/ - // For compatibility - if ($element == 'order') { $element = $subelement = 'commande'; } - if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } - if ($element == 'contract') { $element = $subelement = 'contrat'; } - if ($element == 'order_supplier') { $element = 'fourn'; $subelement = 'fournisseur.commande'; } + // For compatibility + if ($element == 'order') { $element = $subelement = 'commande'; } + if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'contract') { $element = $subelement = 'contrat'; } + if ($element == 'order_supplier') { $element = 'fourn'; $subelement = 'fournisseur.commande'; } - $facfou->origin = $_POST['origin']; - $facfou->origin_id = $_POST['originid']; + $object->origin = $_POST['origin']; + $object->origin_id = $_POST['originid']; - $facid = $facfou->create($user); + $facid = $object->create($user); - // Add lines - if ($facid > 0) - { - require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'); - $classname = ucfirst($subelement); - if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur'; - $srcobject = new $classname($db); + // Add lines + if ($facid > 0) + { + require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'); + $classname = ucfirst($subelement); + if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur'; + $srcobject = new $classname($db); - $result=$srcobject->fetch($_POST['originid']); - if ($result > 0) - { - $lines = $srcobject->lines; - if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); + $result=$srcobject->fetch($_POST['originid']); + if ($result > 0) + { + $lines = $srcobject->lines; + if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); - $num=count($lines); - for ($i = 0; $i < $num; $i++) - { - $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + $num=count($lines); + for ($i = 0; $i < $num; $i++) + { + $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); - // Dates - // TODO mutualiser - $date_start=$lines[$i]->date_debut_prevue; - if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; - if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; - $date_end=$lines[$i]->date_fin_prevue; - if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; - if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; + // Dates + // TODO mutualiser + $date_start=$lines[$i]->date_debut_prevue; + if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; + if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; + $date_end=$lines[$i]->date_fin_prevue; + if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; + if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; - $result = $facfou->addline( - $desc, - $lines[$i]->subprice, - $lines[$i]->tva_tx, - $lines[$i]->localtax1_tx, - $lines[$i]->localtax2_tx, - $lines[$i]->qty, - $lines[$i]->fk_product, - $lines[$i]->remise_percent, - $date_start, - $date_end, - 0, - $lines[$i]->info_bits, + $result = $object->addline( + $desc, + $lines[$i]->subprice, + $lines[$i]->tva_tx, + $lines[$i]->localtax1_tx, + $lines[$i]->localtax2_tx, + $lines[$i]->qty, + $lines[$i]->fk_product, + $lines[$i]->remise_percent, + $date_start, + $date_end, + 0, + $lines[$i]->info_bits, 'HT', - $product_type - ); + $product_type + ); - if ($result < 0) - { - $error++; - break; - } - } - } - else - { - $error++; - } - } - else - { - $error++; - } - } - // If some invoice's lines already known - else - { - $facid = $facfou->create($user); + if ($result < 0) + { + $error++; + break; + } + } + } + else + { + $error++; + } + } + else + { + $error++; + } + } + // If some invoice's lines already known + else + { + $facid = $object->create($user); if ($facid < 0) { $error++; @@ -326,7 +335,7 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) if (! $error) { - for ($i = 1 ; $i < 9 ; $i++) + for ($i = 1 ; $i < 9 ; $i++) { $label = $_POST['label'.$i]; $amountht = price2num($_POST['amount'.$i]); @@ -346,22 +355,22 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) } $atleastoneline=1; - $product=new Product($db); - $product->fetch($_POST['idprod'.$i]); + $product=new Product($db); + $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); - if ($ret < 0) $error++; - } + $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 ($error) { $langs->load("errors"); $db->rollback(); - $mesg='
'.$langs->trans($facfou->error).'
'; - $_GET['action']='create'; + $mesg='
'.$langs->trans($object->error).'
'; + $action='create'; $_GET['socid']=$_POST['socid']; } 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); - $facfou->fetch($_GET['facid']); - $facfou->deleteline($_GET['lineid']); - $_GET['action'] = 'edit'; + $object->fetch($_GET['facid']); + $object->deleteline($_GET['lineid']); + $action = 'edit'; } // 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); - $facfou->fetch($_GET['facid']); + $object->fetch($_GET['facid']); if ($_POST['puht']) { @@ -413,18 +420,18 @@ if ($_REQUEST['action'] == 'update_line') } else { - if ($facfou->socid) - { - $societe=new Societe($db); - $societe->fetch($facfou->socid); - } + if ($object->socid) + { + $societe=new Societe($db); + $societe->fetch($object->socid); + } $label = $_POST['label']; $type = $_POST["type"]?$_POST["type"]:0; $localtax1tx= get_localtax($_POST['tauxtva'], 1, $societe); - $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) { unset($_POST['label']); @@ -432,25 +439,23 @@ if ($_REQUEST['action'] == 'update_line') } } -if ($_GET['action'] == 'addline') +if ($action == 'addline') { - $facfou = new FactureFournisseur($db); - $ret=$facfou->fetch($_GET['facid']); + $ret=$object->fetch($_GET['facid']); if ($ret < 0) { - dol_print_error($db,$facfou->error); + dol_print_error($db,$object->error); exit; } - if ($facfou->socid) - { - $societe=new Societe($db); - $societe->fetch($facfou->socid); - } + if ($object->socid) + { + $societe=new Societe($db); + $societe->fetch($object->socid); + } if ($_POST['idprodfournprice']) // > 0 or -1 { - $product = new ProductFournisseur($db); $idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']); if ($idprod > 0) { @@ -465,11 +470,11 @@ if ($_GET['action'] == 'addline') $tvatx=get_default_tva($societe,$mysoc,$product->id); $localtax1tx= get_localtax($tvatx, 1, $societe); - $localtax2tx= get_localtax($tvatx, 2, $societe); + $localtax2tx= get_localtax($tvatx, 2, $societe); $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) { @@ -481,8 +486,8 @@ if ($_GET['action'] == 'addline') else { $tauxtva = price2num($_POST['tauxtva']); - $localtax1tx= get_localtax($tauxtva, 1, $societe); - $localtax2tx= get_localtax($tauxtva, 2, $societe); + $localtax1tx= get_localtax($tauxtva, 1, $societe); + $localtax2tx= get_localtax($tauxtva, 2, $societe); if (! $_POST['label']) { @@ -497,14 +502,14 @@ if ($_GET['action'] == 'addline') $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, $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 { $ttc = price2num($_POST['amountttc']); $ht = $ttc / (1 + ($tauxtva / 100)); $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); } } } @@ -529,35 +534,33 @@ if ($_GET['action'] == 'addline') unset($_POST['pu']); unset($_POST['tva_tx']); unset($_POST['label']); - unset($localtax1_tx); - unset($localtax2_tx); + unset($localtax1_tx); + unset($localtax2_tx); } else if (empty($mesg)) { - $mesg='
'.$facfou->error.'
'; + $mesg='
'.$object->error.'
'; } - $_GET['action'] = ''; + $action = ''; } -if ($_POST['action'] == 'classin') +if ($action == 'classin') { - $facture = new FactureFournisseur($db); - $facture->fetch($_GET['facid']); - $result=$facture->setProject($_POST['projectid']); + $object->fetch($_GET['facid']); + $result=$object->setProject($_POST['projectid']); } // 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); - $fac->fetch($_GET['facid']); + $object->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; + $sql.= ' WHERE pf.fk_facturefourn = '.$object->id; $result = $db->query($sql); 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 - //$ventilExportCompta = $fac->getVentilExportCompta(); + //$ventilExportCompta = $object->getVentilExportCompta(); // 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; if (! empty($_REQUEST['lang_id'])) @@ -589,18 +592,17 @@ if ($_GET['action'] == 'edit' && $user->rights->fournisseur->facture->creer) $outputlangs = new Translate("",$conf); $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 = $fac->fetch($_GET['facid']); - if ($fac->statut == 2 - || ($fac->statut == 3 && $fac->close_code != 'replaced')) + $result = $object->fetch($_GET['facid']); + if ($object->statut == 2 + || ($object->statut == 3 && $object->close_code != 'replaced')) { - $result = $fac->set_unpaid($user); + $result = $object->set_unpaid($user); if ($result > 0) { Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']); @@ -608,18 +610,11 @@ if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->facture->creer) } else { - $mesg='
'.$fac->error.'
'; + $mesg='
'.$object->error.'
'; } } } - -/********************************************************************* - * - * Mail Actions - * - **********************************************************************/ - /* * Add file in email form */ @@ -633,8 +628,7 @@ if ($_POST['addfile']) $mesg=dol_add_file_process($upload_dir_tmp,0,0); - $_GET["action"]='presend'; - $_POST["action"]='presend'; + $action='presend'; } /* @@ -650,23 +644,21 @@ if (! empty($_POST['removedfile'])) $mesg=dol_remove_file_process($_POST['removedfile'],0); - $_GET["action"]='presend'; - $_POST["action"]='presend'; + $action='presend'; } /* * Send mail */ -if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) +if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) { $langs->load('mails'); - $facturefourn=new FactureFournisseur($db); - $facturefourn->fetch($_GET['facid']); - $result=$facturefourn->fetch_thirdparty(); + $object->fetch($_GET['facid']); + $result=$object->fetch_thirdparty(); if ($result > 0) { - $ref = dol_sanitizeFileName($facturefourn->ref); + $ref = dol_sanitizeFileName($object->ref); $file = $conf->fournisseur->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; if (is_readable($file)) @@ -682,12 +674,12 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] // Recipient was provided from combo list if ($_POST['receiver'] == 'thirdparty') // Id of third party { - $sendto = $facturefourn->client->email; + $sendto = $object->client->email; $sendtoid = 0; } 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']; } } @@ -702,10 +694,10 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] $sendtocc = $_POST['sendtocc']; $deliveryreceipt = $_POST['deliveryreceipt']; - if ($_POST['action'] == 'send') + if ($action == 'send') { 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'; $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; if ($message) @@ -743,17 +735,17 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] $error=0; // Initialisation donnees - $facturefourn->sendtoid = $sendtoid; - $facturefourn->actiontypecode = $actiontypecode; - $facturefourn->actionmsg = $actionmsg; - $facturefourn->actionmsg2 = $actionmsg2; - $facturefourn->fk_element = $facturefourn->id; - $facturefourn->elementtype = $facturefourn->element; + $object->sendtoid = $sendtoid; + $object->actiontypecode = $actiontypecode; + $object->actionmsg = $actionmsg; + $object->actionmsg2 = $actionmsg2; + $object->fk_element = $object->id; + $object->elementtype = $object->element; // 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); + $result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers @@ -765,7 +757,7 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] { // 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)); + Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&mesg='.urlencode($mesg)); 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.'); } - //$_GET['action'] = 'presend'; + //$action = 'presend'; } /* * 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 - $facture=new FactureFournisseur($db); - $facture->fetch($_REQUEST['facid']); + $object->fetch($_REQUEST['facid']); if ($_REQUEST['model']) { - $facture->setDocModel($user, $_REQUEST['model']); + $object->setDocModel($user, $_REQUEST['model']); } $outputlangs = $langs; @@ -836,7 +822,7 @@ if ($_REQUEST['action'] == 'builddoc') $outputlangs = new Translate("",$conf); $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) { dol_print_error($db,$result); @@ -844,18 +830,17 @@ if ($_REQUEST['action'] == 'builddoc') } 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; } } // Delete file in doc form -if ($action=='remove_file') +if ($action == 'remove_file') { 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 . "/"; $file = $upload_dir . '/' . $_GET['file']; @@ -869,17 +854,17 @@ if ($action=='remove_file') * View */ -llxHeader('','',''); - +$html = new Form($db); $formfile = new FormFile($db); +llxHeader('','',''); // Mode creation -if ($_GET['action'] == 'create') +if ($action == 'create') { print_fiche_titre($langs->trans('NewBill')); - if ($mesg) { print $mesg.'
'; } + dol_htmloutput_mesg($mesg); $societe=''; if ($_GET['socid']) @@ -888,53 +873,53 @@ if ($_GET['action'] == 'create') $societe->fetch($_GET['socid']); } - if (GETPOST('origin') && GETPOST('originid')) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = GETPOST('origin'); + if (GETPOST('origin') && GETPOST('originid')) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = GETPOST('origin'); - if ($element == 'project') - { + if ($element == 'project') + { $projectid=GETPOST('originid'); - } - else if (in_array($element,array('order_supplier'))) - { - // For compatibility - if ($element == 'order') { $element = $subelement = 'commande'; } - if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } - if ($element == 'contract') { $element = $subelement = 'contrat'; } - if ($element == 'order_supplier') { $element = 'fourn'; $subelement = 'fournisseur.commande'; } + } + else if (in_array($element,array('order_supplier'))) + { + // For compatibility + if ($element == 'order') { $element = $subelement = 'commande'; } + if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'contract') { $element = $subelement = 'contrat'; } + if ($element == 'order_supplier') { $element = 'fourn'; $subelement = 'fournisseur.commande'; } - require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'); - $classname = ucfirst($subelement); - if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur'; - $objectsrc = new $classname($db); - $objectsrc->fetch(GETPOST('originid')); - $objectsrc->fetch_thirdparty(); + require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'); + $classname = ucfirst($subelement); + if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur'; + $objectsrc = new $classname($db); + $objectsrc->fetch(GETPOST('originid')); + $objectsrc->fetch_thirdparty(); - $projectid = (!empty($objectsrc->fk_project)?$object->fk_project:''); - //$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:''); + $projectid = (!empty($objectsrc->fk_project)?$object->fk_project:''); + //$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:''); - $soc = $objectsrc->client; - $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); - $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); - $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); - $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); - $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; + $soc = $objectsrc->client; + $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); + $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); + $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); + $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); + $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; - $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); - } - } - else - { - $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); + } + } + else + { + $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 ''; @@ -943,10 +928,10 @@ if ($_GET['action'] == 'create') print ''; print ''; - // Ref - print ''; + // Ref + print ''; - // Third party + // Third party print ''; print ''; print ''; - print ''; - // Label + // Label print ''; // Date invoice @@ -1058,7 +1043,7 @@ if ($_GET['action'] == 'create') print ''; // Due date - print ''; @@ -1066,68 +1051,68 @@ if ($_GET['action'] == 'create') print ''; print ''; - if (is_object($objectsrc)) - { - print "\n"; - print "\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''; - print ''; + if (is_object($objectsrc)) + { + print "\n"; + print "\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''; + print ''; - $txt=$langs->trans($classname); - if ($classname=='CommandeFournisseur') $txt=$langs->trans("SupplierOrder"); - print ''; - print ''; - print '"; - if ($mysoc->pays_code=='ES') - { - if ($mysoc->localtax1_assuj=="1") //Localtax1 RE - { - print '"; - } + $txt=$langs->trans($classname); + if ($classname=='CommandeFournisseur') $txt=$langs->trans("SupplierOrder"); + print ''; + print ''; + print '"; + if ($mysoc->pays_code=='ES') + { + if ($mysoc->localtax1_assuj=="1") //Localtax1 RE + { + print '"; + } - if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF - { - print '"; - } - } - print '"; - } + if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF + { + print '"; + } + } + print '"; + } else { - if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - for ($i = 1 ; $i < 9 ; $i++) - { - $value_qty = '1'; - $value_tauxtva = ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - } - } + for ($i = 1 ; $i < 9 ; $i++) + { + $value_qty = '1'; + $value_tauxtva = ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + } } - // Bouton "Create Draft" - print "
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('ThirdParty').''; @@ -965,91 +950,91 @@ if ($_GET['action'] == 'create') print '
'.$langs->trans('RefSupplier').'
'.$langs->trans('Type').''; - print ''."\n"; + print ''; + // Credit note + print ''."\n"; + */ + print '
'.$langs->trans('Type').''; + print ''."\n"; - // Standard invoice - print ''."\n"; + // Standard invoice + print ''."\n"; - /* - // Deposit - print ''."\n"; + /* + // Deposit + print ''."\n"; - // Proforma - if ($conf->global->FACTURE_USE_PROFORMAT) - { - print ''."\n"; - } + // Proforma + if ($conf->global->FACTURE_USE_PROFORMAT) + { + print ''."\n"; + } - // Replacement - print ''; + // Replacement + print ''; - // Credit note - print ''."\n"; -*/ - print '
'; - print ''; - print ''; - $desc=$html->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1); - print $desc; - print '
'; + print ''; + print ''; + $desc=$html->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1); + print $desc; + print '
'; - print ''; - print ''; - $desc=$html->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1); - print $desc; - print '
'; + print ''; + print ''; + $desc=$html->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1); + print $desc; + print '
'; - print ''; - print ''; - $desc=$html->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1); - print $desc; - print '
'; + print ''; + print ''; + $desc=$html->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1); + print $desc; + print '
'; - print ''; - print ''; - $text=$langs->trans("InvoiceReplacementAsk").' '; - $text.=''; - $desc=$html->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1); - print $desc; - print '
'; + print ''; + print ''; + $text=$langs->trans("InvoiceReplacementAsk").' '; + $text.=''; + $desc=$html->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1); + print $desc; + print '
'; - print ''; - print ''; - $text=$langs->transnoentities("InvoiceAvoirAsk").' '; - // $text.=''; - $text.=''; - $desc=$html->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1); - //.' ('.$langs->trans("FeatureNotYetAvailable").')',$langs->transnoentities("InvoiceAvoirDesc"),1); - print $desc; - print '
'; - print '
'; + print ''; + print ''; + $text=$langs->transnoentities("InvoiceAvoirAsk").' '; + // $text.=''; + $text.=''; + $desc=$html->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1); + //.' ('.$langs->trans("FeatureNotYetAvailable").')',$langs->transnoentities("InvoiceAvoirDesc"),1); + print $desc; + print '
'; + print '
'.$langs->trans('Label').'
'.$langs->trans('DateEcheance').''; + print '
'.$langs->trans('DateMaxPayment').''; $html->select_date($datedue,'ech','','','',"add",1,1); print '
'.$txt.''.$objectsrc->getNomUrl(1).'
'.$langs->trans('TotalHT').''.price($objectsrc->total_ht).'
'.$langs->trans('TotalVAT').''.price($objectsrc->total_tva)."
'.$langs->transcountry("AmountLT1",$mysoc->pays_code).''.price($objectsrc->total_localtax1)."
'.$txt.''.$objectsrc->getNomUrl(1).'
'.$langs->trans('TotalHT').''.price($objectsrc->total_ht).'
'.$langs->trans('TotalVAT').''.price($objectsrc->total_tva)."
'.$langs->transcountry("AmountLT1",$mysoc->pays_code).''.price($objectsrc->total_localtax1)."
'.$langs->transcountry("AmountLT2",$mysoc->pays_code).''.price($objectsrc->total_localtax2)."
'.$langs->trans('TotalTTC').''.price($objectsrc->total_ttc)."
'.$langs->transcountry("AmountLT2",$mysoc->pays_code).''.price($objectsrc->total_localtax2)."
'.$langs->trans('TotalTTC').''.price($objectsrc->total_ttc)."
 '.$langs->trans('Label').''.$langs->trans('PriceUHT').''.$langs->trans('VAT').''.$langs->trans('Qty').''.$langs->trans('PriceUTTC').'
 '.$langs->trans('Label').''.$langs->trans('PriceUHT').''.$langs->trans('VAT').''.$langs->trans('Qty').''.$langs->trans('PriceUTTC').'
'.$i.''; - print $html->load_tva('tauxtva'.$i,$value_tauxtva,$societe,$mysoc); - print '
'.$i.''; + print $html->load_tva('tauxtva'.$i,$value_tauxtva,$societe,$mysoc); + print '
\n"; + // Bouton "Create Draft" + print "\n"; - print '
'; + print '
'; - print "
\n"; + print "\n"; } else { @@ -1149,598 +1134,529 @@ else $societe = new Fournisseur($db); $societe->fetch($fac->socid); - if ($_GET['action'] == 'edit') + /* + * View card + */ + $head = facturefourn_prepare_head($fac); + $titre=$langs->trans('SupplierInvoice'); + dol_fiche_head($head, 'card', $titre, 0, 'bill'); + + dol_htmloutput_mesg($mesg); + + // Confirmation de la suppression d'une ligne produit + if ($action == 'confirm_delete_line') { - print_fiche_titre($langs->trans('SupplierInvoice')); - - print '
'; - print ''; - print ''; - - print ''; - - print ''; - print ''; - print ''; - print ''; - - // Ref - print ''; - $rownb=10; - print ''; - - // Ref supplier - print ''; - print ''; - - // Label - print ''; - - // Date invoice - print ''; - - // Due date - print ''; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print '
'.$langs->trans('Company').''.$societe->getNomUrl(1).''.$langs->trans('NotePublic').'
'.$langs->trans('Ref').''; - print $fac->ref.''; - print '
'.$langs->trans('RefSupplier').''; - print '
'.$langs->trans('Label').''; - print '
'.$langs->trans('DateInvoice').''; - $html->select_date($fac->datep,'','','','',"update",1,1); - 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 '
'.$langs->trans('AmountHT').''.price($fac->total_ht).'
'.$langs->trans('AmountVAT').''.price($fac->total_tva).'
'.$langs->trans('AmountTTC').''.price($fac->total_ttc).'
'.$langs->trans('Status').''.$fac->getLibStatut(4).'
'; - print ''; - print '     '; - print ''; - - print '
'; - print '
'; - - print ''; + $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 '
'; } - else + + // Clone confirmation + if ($action == 'clone') { - /* - * View card - */ - $head = facturefourn_prepare_head($fac); - $titre=$langs->trans('SupplierInvoice'); - dol_fiche_head($head, 'card', $titre, 0, 'bill'); + // 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 '
'; + } - if ($mesg) { print $mesg.'
'; } + // Confirmation de la validation + if ($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 suppression d'une ligne produit - if ($_GET['action'] == 'confirm_delete_line') + // Confirmation set 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); + if ($ret == 'html') print '
'; + } + + /* + * Confirmation de la suppression de la facture fournisseur + */ + if ($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 ''; + + // Ref + print ''; + print "\n"; + + // Ref supplier + print ''; + + // Third party + print ''; + print ''; + + // Type + print ''; - /* - * Facture - */ - print '
'.$langs->trans("Ref").''; + print $html->showrefnav($fac,'facid','',1,'rowid','ref',$morehtmlref); + 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 '
'.$langs->trans('Supplier').''.$societe->getNomUrl(1); + print '   ('.$langs->trans('OtherBills').')
'.$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 (count($facidavoir) > 0) + { + print ' ('.$langs->transnoentities("InvoiceHasAvoir"); + $i=0; + foreach($facidavoir as $id) { - $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 '
'; - } - - // 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 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 '
'; + 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 ''; - // Ref - print ''; - print "\n"; + /* + * List of payments + */ + $nbrows=7; + if ($conf->projet->enabled) $nbrows++; - // Ref supplier - print ''; + // Local taxes + if ($mysoc->pays_code=='ES') + { + if($mysoc->localtax1_assuj=="1") $nbrow++; + if($mysoc->localtax2_assuj=="1") $nbrow++; + } - // Third party - print ''; + print ''; + print ''; - /* - * Lines - */ - print '
'; - print '
'.$html->editfieldkey("Label",'label',$fac->label,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer)).''; + print $html->editfieldval("Label",'label',$fac->label,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer)); + print '
'.$langs->trans("Ref").''; - print $html->showrefnav($fac,'facid','',1,'rowid','ref',$morehtmlref); - 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 '
'.$langs->trans('Supplier').''.$societe->getNomUrl(1); - print '   ('.$langs->trans('OtherBills').')'; + $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 ''; + print ''; + print ''; + print ''; print ''; - // Type - print ''; - - - // Label - print ''; - - /* - * 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++; - } - - print ''; - - - print ''; - - // Date - print ''; - - // Due date - print ''; - print ''; - - // Status - $alreadypaid=$fac->getSommePaiement(); - print ''; - - print ''; - print ''; - - // Amount Local Taxes - if ($mysoc->pays_code=='ES') - { - if ($mysoc->localtax1_assuj=="1") //Localtax1 RE - { - print ''; - print ''; - print ''; - } - if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF - { - print ''; - print ''; - print ''; - } - } - print ''; - - // Project - if ($conf->projet->enabled) - { - $langs->load('projects'); - print ''; - print ''; print ''; + $totalpaye += $objp->amount; + $i++; } + if ($fac->paye == 0) + { + print ''; + print ''; + + $resteapayer = $fac->total_ttc - $totalpaye; + + print ''; + print ''; + } print '
'.$langs->trans('Payments').''.$langs->trans('Type').''.$langs->trans('Amount').' 
'.$langs->trans('Type').''; - print $fac->getLibType(); - if ($fac->type == 1) + $var=True; + while ($i < $num) { - $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 (count($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 '
'.$html->editfieldkey("Label",'label',$fac->label,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer)).''; - print $html->editfieldval("Label",'label',$fac->label,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer)); - 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 ''; - print ''; - + $objp = $db->fetch_object($result); + $var=!$var; + print ''; + print '\n"; + print ''; + print ''; + print ' '; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ''; - print '\n"; - print ''; - print ''; - - if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) - { - print ''; - } - - print ''; - $totalpaye += $objp->amount; - $i++; - } - - if ($fac->paye == 0) - { - print ''; - print ''; - - $resteapayer = $fac->total_ttc - $totalpaye; - - print ''; - print ''; - } - print '
'.$langs->trans('Payments').''.$langs->trans('Type').'
'.img_object($langs->trans('ShowPayment'),'payment').' '.dol_print_date($db->jdate($objp->dp),'day')."'.$objp->paiement_type.' '.$objp->num_paiement.''.price($objp->amount).''; if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) { - $tdsup=' colspan="2"'; - } - print ''.$langs->trans('AmountTTC').'
'.img_object($langs->trans('ShowPayment'),'payment').' '.dol_print_date($db->jdate($objp->dp),'day')."'.$objp->paiement_type.' '.$objp->num_paiement.''.price($objp->amount).' '.$langs->trans('Currency'.$conf->monnaie).''; - print ''; - print img_delete(); - print '
'.$langs->trans('AlreadyPaid').' :'.price($totalpaye).' '.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans("Billed").' :'.price($fac->total_ttc).' '.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('RemainderToPay').' :'.price($resteapayer).' '.$langs->trans('Currency'.$conf->monnaie).'
'; - $db->free($result); - } - else - { - dol_print_error($db); - } - print '
'.$langs->trans('Date').''; - print dol_print_date($fac->datep,'daytext').'
'.$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 '
'.$langs->trans('Status').''.$fac->getLibStatut(4,$alreadypaid).'
'.$langs->trans('AmountHT').''.price($fac->total_ht).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($fac->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->transcountry("AmountLT1",$mysoc->pays_code).''.price($fac->total_localtax1).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->transcountry("AmountLT2",$mysoc->pays_code).''.price($fac->total_localtax2).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($fac->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'; - - print ''; - if ($_GET['action'] != 'classify') - { - print ''; - } - print '
'; - print $langs->trans('Project'); - print 'id.'">'; - print img_edit($langs->trans('SetProject'),1); - print '
'; - - print '
'; - if ($_GET['action'] == 'classify') - { - $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 img_delete(); + print ''; } print '
'.$langs->trans('AlreadyPaid').' :'.price($totalpaye).'
'.$langs->trans("Billed").' :'.price($fac->total_ttc).'
'.$langs->trans('RemainderToPay').' :'.price($resteapayer).'
'; + $db->free($result); + } + else + { + dol_print_error($db); + } + print '
'; - $var=1; - $num=count($fac->lines); - for ($i = 0; $i < $num; $i++) + // Date + print ''; + + // Due date + print ''; + + // Status + $alreadypaid=$fac->getSommePaiement(); + print ''; + + print ''; + print ''; + + // Amount Local Taxes + if ($mysoc->pays_code=='ES') + { + if ($mysoc->localtax1_assuj=="1") //Localtax1 RE { - if ($i == 0) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - 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; - - $var=!$var; - - // Edit line - if ($fac->statut == 0 && $_GET['action'] == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['lineid'] == $fac->lines[$i]->rowid) - { - print 'lines[$i]->rowid.'" method="post">'; - print ''; - print ''; - print ''; - - // Show product and description - print ''; - - // VAT - print ''; - - // Unit price - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - print ''; - } - else // Affichage simple de la ligne - { - print ''; - - // Show product and description - print ''; - - // VAT - print ''; - - // Unit price - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - } - + print ''; + print ''; + print ''; } - - /* - * Form to add new line - */ - - if ($fac->statut == 0 && $_GET['action'] != 'mod_ligne') + if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF { - print ''; - print ''; + print ''; + print ''; + print ''; + } + } + print ''; + + // Project + if ($conf->projet->enabled) + { + $langs->load('projects'); + print ''; + print ''; + print ''; + } + + print '
'.$html->editfieldkey("Date",'date',$fac->datep,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0)).''; + print $html->editfieldval("Date",'date',$fac->datep,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0),'day'); + print '
'.$html->editfieldkey("DateMaxPayment",'date_echeance',$fac->date_echeance,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0)).''; + 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 '
'.$langs->trans('Status').''.$fac->getLibStatut(4,$alreadypaid).'
'.$langs->trans('AmountHT').''.price($fac->total_ht).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($fac->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('Label').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('PriceUTTC').''.$langs->trans('Qty').''.$langs->trans('TotalHTShort').''.$langs->trans('TotalTTCShort').'  
'; - 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"); - $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,'',128,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); - $doleditor->Create(); - print '
'; - print $html->load_tva('tauxtva',$fac->lines[$i]->tva_tx,$societe,$mysoc); - print '  '; - 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); - - // 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):''; - } - - // 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 '
'.vatrate($fac->lines[$i]->tva_tx).'%'.price($fac->lines[$i]->pu_ht,'MU').''.($fac->lines[$i]->pu_ttc?price($fac->lines[$i]->pu_ttc,'MU'):' ').''.$fac->lines[$i]->qty.''.price($fac->lines[$i]->total_ht).''.price($fac->lines[$i]->total_ttc).''; - if ($fac->statut == 0) print ''.img_edit().''; - else print ' '; - print ''; - if ($fac->statut == 0) print ''.img_delete().''; - else print ' '; - print '
'.$langs->transcountry("AmountLT1",$mysoc->pays_code).''.price($fac->total_localtax1).''.$langs->trans("Currency".$conf->monnaie).'
'; - print ''; // ancre - print $langs->trans('AddNewLine').' - '.$langs->trans("FreeZone").'
'.$langs->transcountry("AmountLT2",$mysoc->pays_code).''.price($fac->total_localtax2).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($fac->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'; + + print ''; + if ($action != 'classify') + { + print ''; + } + print '
'; + print $langs->trans('Project'); + print 'id.'">'; + print img_edit($langs->trans('SetProject'),1); + print '
'; + + print '
'; + if ($action == 'classify') + { + $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 '
'; + + + /* + * Lines + */ + print '
'; + print ''; + $var=1; + $num=count($fac->lines); + for ($i = 0; $i < $num; $i++) + { + if ($i == 0) + { + print ''; print ''; print ''; print ''; print ''; - print ''; - print ''; + print ''; + print ''; print ''; print ''; print ''; + } - // Add free products/services form - 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; + + $var=!$var; + + // Edit line + if ($fac->statut == 0 && $action == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['lineid'] == $fac->lines[$i]->rowid) + { + print 'lines[$i]->rowid.'" method="post">'; print ''; - print ''; - print ''; - - $var=true; + print ''; print ''; + + // Show product and description print ''; - print ''; + // VAT print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + + // Unit price + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; print ''; + } + else // Affichage simple de la ligne + { + print ''; - // Ajout de produits/services predefinis - if ($conf->product->enabled || $conf->service->enabled) + // Show product and description + print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; // ancre pour retourner sur la ligne - print ''; - print ''; - print ''; - print ''; - print ''; - $var=! $var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + $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); + + // 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); + + // Show range + print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end); + } + print ''; + + // VAT + print ''; + + // Unit price + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; } - print '
'.$langs->trans('Label').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('PriceUTTC').''.$langs->trans('Qty').'  '.$langs->trans('TotalHTShort').''.$langs->trans('TotalTTCShort').'  
'; + 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 '
'; + } - $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 + // 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',GETPOST("label"),'',100,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); + $doleditor=new DolEditor('label',$fac->lines[$i]->description,'',128,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); $doleditor->Create(); + print '
'; - print $html->load_tva('tauxtva',($_POST["tauxtva"]?$_POST["tauxtva"]:-1),$societe,$mysoc); + print $html->load_tva('tauxtva',$fac->lines[$i]->tva_tx,$societe,$mysoc); print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '  
  '; + print '
'; + if ($fac->lines[$i]->fk_product) { - print '
'; - print $langs->trans("AddNewLine").' - '; - if ($conf->service->enabled) - { - print $langs->trans('RecordedProductsAndServices'); - } - else - { - print $langs->trans('RecordedProducts'); - } - print ''.$langs->trans('Qty').'  
'; - $html->select_produits_fournisseurs($fac->socid,'','idprodfournprice','',$filtre); - print '  
'.vatrate($fac->lines[$i]->tva_tx).'%'.price($fac->lines[$i]->pu_ht,'MU').''.($fac->lines[$i]->pu_ttc?price($fac->lines[$i]->pu_ttc,'MU'):' ').''.$fac->lines[$i]->qty.''.price($fac->lines[$i]->total_ht).''.price($fac->lines[$i]->total_ttc).''; + if ($fac->statut == 0) print ''.img_edit().''; + else print ' '; + print ''; + if ($fac->statut == 0) print ''.img_delete().''; + else print ' '; + print '
'; - - print ''; } - if ($_GET['action'] != 'presend') + /* + * Form to add new line + */ + + if ($fac->statut == 0 && $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 ''; + + $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 '
'; + + // 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',GETPOST("label"),'',100,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); + $doleditor->Create(); + + print ''; + print ''; + print $html->load_tva('tauxtva',($_POST["tauxtva"]?$_POST["tauxtva"]:-1),$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 ''; + + 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 ''; + + 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 ''.$langs->trans('Modify').''; - } - // Send by mail if (($fac->statut == 1 || $fac->statut == 2)) { @@ -1780,13 +1690,13 @@ else //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 ''.$langs->trans('DoPayment').''; } //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 ''.$langs->trans('ClassifyPaid').''; @@ -1795,7 +1705,7 @@ else } //Validate - if ($_GET['action'] != 'edit' && $fac->statut == 0) + if ($action != 'edit' && $fac->statut == 0) { if (count($fac->lines)) { @@ -1813,19 +1723,19 @@ else } //Clone - if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->creer) + if ($action != 'edit' && $user->rights->fournisseur->facture->creer) { print ''.$langs->trans('ToClone').''; } //Delete - if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->supprimer) + if ($action != 'edit' && $user->rights->fournisseur->facture->supprimer) { print ''.$langs->trans('Delete').''; } print ''; - if ($_GET['action'] != 'edit') + if ($action != 'edit') { print '
'; print ''; // ancre @@ -1865,7 +1775,7 @@ else /* * Show mail form */ - if ($_GET['action'] == 'presend') + if ($action == 'presend') { $ref = dol_sanitizeFileName($fac->ref); $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($fac->id,2).$ref.'.pdf'; diff --git a/htdocs/lib/fourn.lib.php b/htdocs/lib/fourn.lib.php index 8f4695ab885..9987d260112 100644 --- a/htdocs/lib/fourn.lib.php +++ b/htdocs/lib/fourn.lib.php @@ -19,9 +19,16 @@ /** * \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) { global $langs, $conf; @@ -29,7 +36,7 @@ function facturefourn_prepare_head($object) $head = array(); $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'; $h++; diff --git a/htdocs/lib/invoice.lib.php b/htdocs/lib/invoice.lib.php index 39f1d508e73..22b0b276571 100644 --- a/htdocs/lib/invoice.lib.php +++ b/htdocs/lib/invoice.lib.php @@ -18,10 +18,16 @@ /** * \file htdocs/lib/invoice.lib.php - * \brief Ensemble de fonctions de base pour le module factures + * \brief Functions used by invoice module * \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) { global $langs, $conf;