diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 10a7b142827..d7b2a85748a 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -23,27 +23,27 @@ */ /** - \file htdocs/fourn/facture/fiche.php - \ingroup facture - \brief Page des la fiche facture fournisseur - \version $Revision$ + \file htdocs/fourn/facture/fiche.php + \ingroup facture + \brief Page des la fiche facture fournisseur + \version $Revision$ */ require('./pre.inc.php'); require('./paiementfourn.class.php'); if (!$user->rights->fournisseur->facture->lire) - accessforbidden(); + accessforbidden(); $langs->load('bills'); $langs->load('suppliers'); $langs->load('companies'); // Sécurité accés client -if ($user->societe_id > 0) +if ($user->societe_id > 0) { - $action = ''; - $socidp = $user->societe_id; + $action = ''; + $socidp = $user->societe_id; } @@ -53,183 +53,170 @@ $action=isset($_GET['action'])?$_GET['action']:$_POST['action']; if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->facture->valider) { - $facturefourn=new FactureFournisseur($db); - $facturefourn->fetch($_GET['facid']); - + $facturefourn=new FactureFournisseur($db); + $facturefourn->fetch($_GET['facid']); $facturefourn->set_valid($user); - - Header('Location: fiche.php?facid='.$_GET['facid']); - exit; + Header('Location: fiche.php?facid='.$_GET['facid']); + exit; } if ($_GET['action'] == 'payed') { - $facturefourn=new FactureFournisseur($db); - $facturefourn->fetch($_GET['facid']); - + $facturefourn=new FactureFournisseur($db); + $facturefourn->fetch($_GET['facid']); $facturefourn->set_payed($user); } if($_GET['action'] == 'deletepaiement') { - $facfou = new FactureFournisseur($db); - $facfou->fetch($_GET['facid']); - if ($facfou->statut == 1 && $facfou->paye == 0 && $user->societe_id == 0) - { - $paiementfourn = new PaiementFourn($db); - $paiementfourn->delete($_GET['paiement_id']); - } + $facfou = new FactureFournisseur($db); + $facfou->fetch($_GET['facid']); + if ($facfou->statut == 1 && $facfou->paye == 0 && $user->societe_id == 0) + { + $paiementfourn = new PaiementFourn($db); + $paiementfourn->fetch($_GET['paiement_id']); + $paiementfourn->delete(); + } } if ($_POST['action'] == 'modif_libelle') { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set libelle = \''.$form_libelle.'\' WHERE rowid = '.$_GET['facid']; - $result = $db->query( $sql); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set libelle = \''.$form_libelle.'\' WHERE rowid = '.$_GET['facid']; + $result = $db->query( $sql); } if ($_POST['action'] == 'update') { - $datefacture = $db->idate(mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"])); - $date_echeance = $db->idate(mktime(12,0,0,$_POST["echmonth"],$_POST["echday"],$_POST["echyear"])); + $datefacture = $db->idate(mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear'])); + $date_echeance = $db->idate(mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear'])); - $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set '; - $sql .= " facnumber='".trim($_POST["facnumber"])."'"; - $sql .= ", libelle='".trim($_POST["libelle"])."'"; - $sql .= ", note='".$_POST["note"]."'"; - $sql .= ", datef = '$datefacture'"; - $sql .= ", date_lim_reglement = '$date_echeance'"; - $sql .= " WHERE rowid = ".$_GET['facid']." ;"; - $result = $db->query( $sql); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set '; + $sql .= " facnumber='".trim($_POST['facnumber'])."'"; + $sql .= ", libelle='".trim($_POST['libelle'])."'"; + $sql .= ", note='".$_POST['note']."'"; + $sql .= ", datef = '$datefacture'"; + $sql .= ", date_lim_reglement = '$date_echeance'"; + $sql .= ' WHERE rowid = '.$_GET['facid'].' ;'; + $result = $db->query( $sql); } /* * Action création */ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) { - if ($_POST['facnumber']) - { - $datefacture = mktime(12,0,0, - $_POST["remonth"], - $_POST["reday"], - $_POST["reyear"]); + if ($_POST['facnumber']) + { + $datefacture = mktime(12,0,0, + $_POST['remonth'], + $_POST['reday'], + $_POST['reyear']); - $tva = 0; - $tva = ($_POST['tva_taux'] * $_POST['amount']) / 100 ; - $remise = 0; - $total = $tva + $_POST['amount']; + $tva = 0; + $amo = price2num($_POST['amount']); + $tva = (price2num($_POST['tva_taux']) * $amo) / 100 ; + $remise = 0; + $total = $tva + $amo; - $db->begin(); + $db->begin(); - // Creation facture - $facfou = new FactureFournisseur($db); + // Creation facture + $facfou = new FactureFournisseur($db); - $facfou->number = $_POST["facnumber"]; - $facfou->socid = $_POST["socidp"]; - $facfou->libelle = $_POST["libelle"]; - $facfou->date = $datefacture; - $facfou->date_echeance = mktime(12,0,0,$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); - $facfou->note = $_POST["note"]; + $facfou->ref = $_POST['facnumber']; + $facfou->socidp = $_POST['socidp']; + $facfou->libelle = $_POST['libelle']; + $facfou->date = $datefacture; + $facfou->date_echeance = mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); + $facfou->note = $_POST['note']; - $facid = $facfou->create($user); + $facid = $facfou->create($user); - // Ajout des lignes de factures - if ($facid > 0) - { - for ($i = 1 ; $i < 9 ; $i++) - { - $label = 'label'.$i; - $amount = 'amount'.$i; - $amountttc = 'amountttc'.$i; - $tauxtva = 'tauxtva'.$i; - $qty = 'qty'.$i; + // Ajout des lignes de factures + if ($facid > 0) + { + for ($i = 1 ; $i < 9 ; $i++) + { + $label = $_POST['label'.$i]; + $amount = price2num($_POST['amount'.$i]); + $amountttc = price2num($_POST['amountttc'.$i]); + $tauxtva = price2num($_POST['tauxtva'.$i]); + $qty = $_POST['qty'.$i]; - if (strlen($_POST[$label]) > 0 && !empty($_POST[$amount])) - { - $ht = $_POST[$amount]; - $ht = str_replace(' ', '', $ht); - $ht = str_replace(',', '.', $ht); - $atleastoneline=1; - $ret=$facfou->addline($_POST["$label"], $_POST["$amount"], $_POST["$tauxtva"], $_POST["$qty"], 1); - if ($ret < 0) $nberror++; - } - else if (strlen($_POST[$label]) > 0 && empty($_POST[$amount])) - { - $ttc = $_POST[$amountttc]; - $ttc = str_replace(' ', '', $ttc); - $ttc = str_replace(',', '.', $ttc); - $ht = $ttc / (1 + ($_POST[$tauxtva] / 100)); - $atleastoneline=1; - $ret=$facfou->addline($_POST[$label], $ht, $_POST[$tauxtva], $_POST[$qty], 1); - if ($ret < 0) $nberror++; - } - } - if ($nberror) - { - $db->rollback(); - $mesg='