Task #4773 : Gestion des paiements fournisseur
This commit is contained in:
parent
b33e5285a0
commit
cc0939ecde
@ -55,9 +55,7 @@ if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->
|
|||||||
{
|
{
|
||||||
$facturefourn=new FactureFournisseur($db);
|
$facturefourn=new FactureFournisseur($db);
|
||||||
$facturefourn->fetch($_GET['facid']);
|
$facturefourn->fetch($_GET['facid']);
|
||||||
|
|
||||||
$facturefourn->set_valid($user);
|
$facturefourn->set_valid($user);
|
||||||
|
|
||||||
Header('Location: fiche.php?facid='.$_GET['facid']);
|
Header('Location: fiche.php?facid='.$_GET['facid']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -67,7 +65,6 @@ if ($_GET['action'] == 'payed')
|
|||||||
{
|
{
|
||||||
$facturefourn=new FactureFournisseur($db);
|
$facturefourn=new FactureFournisseur($db);
|
||||||
$facturefourn->fetch($_GET['facid']);
|
$facturefourn->fetch($_GET['facid']);
|
||||||
|
|
||||||
$facturefourn->set_payed($user);
|
$facturefourn->set_payed($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +75,8 @@ if($_GET['action'] == 'deletepaiement')
|
|||||||
if ($facfou->statut == 1 && $facfou->paye == 0 && $user->societe_id == 0)
|
if ($facfou->statut == 1 && $facfou->paye == 0 && $user->societe_id == 0)
|
||||||
{
|
{
|
||||||
$paiementfourn = new PaiementFourn($db);
|
$paiementfourn = new PaiementFourn($db);
|
||||||
$paiementfourn->delete($_GET['paiement_id']);
|
$paiementfourn->fetch($_GET['paiement_id']);
|
||||||
|
$paiementfourn->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,16 +89,16 @@ if ($_POST['action'] == 'modif_libelle')
|
|||||||
|
|
||||||
if ($_POST['action'] == 'update')
|
if ($_POST['action'] == 'update')
|
||||||
{
|
{
|
||||||
$datefacture = $db->idate(mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]));
|
$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"]));
|
$date_echeance = $db->idate(mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']));
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set ';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set ';
|
||||||
$sql .= " facnumber='".trim($_POST["facnumber"])."'";
|
$sql .= " facnumber='".trim($_POST['facnumber'])."'";
|
||||||
$sql .= ", libelle='".trim($_POST["libelle"])."'";
|
$sql .= ", libelle='".trim($_POST['libelle'])."'";
|
||||||
$sql .= ", note='".$_POST["note"]."'";
|
$sql .= ", note='".$_POST['note']."'";
|
||||||
$sql .= ", datef = '$datefacture'";
|
$sql .= ", datef = '$datefacture'";
|
||||||
$sql .= ", date_lim_reglement = '$date_echeance'";
|
$sql .= ", date_lim_reglement = '$date_echeance'";
|
||||||
$sql .= " WHERE rowid = ".$_GET['facid']." ;";
|
$sql .= ' WHERE rowid = '.$_GET['facid'].' ;';
|
||||||
$result = $db->query( $sql);
|
$result = $db->query( $sql);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -111,26 +109,27 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
|
|||||||
if ($_POST['facnumber'])
|
if ($_POST['facnumber'])
|
||||||
{
|
{
|
||||||
$datefacture = mktime(12,0,0,
|
$datefacture = mktime(12,0,0,
|
||||||
$_POST["remonth"],
|
$_POST['remonth'],
|
||||||
$_POST["reday"],
|
$_POST['reday'],
|
||||||
$_POST["reyear"]);
|
$_POST['reyear']);
|
||||||
|
|
||||||
$tva = 0;
|
$tva = 0;
|
||||||
$tva = ($_POST['tva_taux'] * $_POST['amount']) / 100 ;
|
$amo = price2num($_POST['amount']);
|
||||||
|
$tva = (price2num($_POST['tva_taux']) * $amo) / 100 ;
|
||||||
$remise = 0;
|
$remise = 0;
|
||||||
$total = $tva + $_POST['amount'];
|
$total = $tva + $amo;
|
||||||
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
// Creation facture
|
// Creation facture
|
||||||
$facfou = new FactureFournisseur($db);
|
$facfou = new FactureFournisseur($db);
|
||||||
|
|
||||||
$facfou->number = $_POST["facnumber"];
|
$facfou->ref = $_POST['facnumber'];
|
||||||
$facfou->socid = $_POST["socidp"];
|
$facfou->socidp = $_POST['socidp'];
|
||||||
$facfou->libelle = $_POST["libelle"];
|
$facfou->libelle = $_POST['libelle'];
|
||||||
$facfou->date = $datefacture;
|
$facfou->date = $datefacture;
|
||||||
$facfou->date_echeance = mktime(12,0,0,$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]);
|
$facfou->date_echeance = mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
|
||||||
$facfou->note = $_POST["note"];
|
$facfou->note = $_POST['note'];
|
||||||
|
|
||||||
$facid = $facfou->create($user);
|
$facid = $facfou->create($user);
|
||||||
|
|
||||||
@ -139,29 +138,23 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
|
|||||||
{
|
{
|
||||||
for ($i = 1 ; $i < 9 ; $i++)
|
for ($i = 1 ; $i < 9 ; $i++)
|
||||||
{
|
{
|
||||||
$label = 'label'.$i;
|
$label = $_POST['label'.$i];
|
||||||
$amount = 'amount'.$i;
|
$amount = price2num($_POST['amount'.$i]);
|
||||||
$amountttc = 'amountttc'.$i;
|
$amountttc = price2num($_POST['amountttc'.$i]);
|
||||||
$tauxtva = 'tauxtva'.$i;
|
$tauxtva = price2num($_POST['tauxtva'.$i]);
|
||||||
$qty = 'qty'.$i;
|
$qty = $_POST['qty'.$i];
|
||||||
|
|
||||||
if (strlen($_POST[$label]) > 0 && !empty($_POST[$amount]))
|
if (strlen($label) > 0 && !empty($amount))
|
||||||
{
|
{
|
||||||
$ht = $_POST[$amount];
|
|
||||||
$ht = str_replace(' ', '', $ht);
|
|
||||||
$ht = str_replace(',', '.', $ht);
|
|
||||||
$atleastoneline=1;
|
$atleastoneline=1;
|
||||||
$ret=$facfou->addline($_POST["$label"], $_POST["$amount"], $_POST["$tauxtva"], $_POST["$qty"], 1);
|
$ret=$facfou->addline($label, $amount, $tauxtva, $qty, 1);
|
||||||
if ($ret < 0) $nberror++;
|
if ($ret < 0) $nberror++;
|
||||||
}
|
}
|
||||||
else if (strlen($_POST[$label]) > 0 && empty($_POST[$amount]))
|
else if (strlen($label) > 0 && empty($amount))
|
||||||
{
|
{
|
||||||
$ttc = $_POST[$amountttc];
|
$ht = $amountttc / (1 + ($tauxtva / 100));
|
||||||
$ttc = str_replace(' ', '', $ttc);
|
|
||||||
$ttc = str_replace(',', '.', $ttc);
|
|
||||||
$ht = $ttc / (1 + ($_POST[$tauxtva] / 100));
|
|
||||||
$atleastoneline=1;
|
$atleastoneline=1;
|
||||||
$ret=$facfou->addline($_POST[$label], $ht, $_POST[$tauxtva], $_POST[$qty], 1);
|
$ret=$facfou->addline($label, $ht, $tauxtva, $qty, 1);
|
||||||
if ($ret < 0) $nberror++;
|
if ($ret < 0) $nberror++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,7 +162,7 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
|
|||||||
{
|
{
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
$mesg='<div class="error">'.$facfou->error.'</div>';
|
$mesg='<div class="error">'.$facfou->error.'</div>';
|
||||||
$_GET["action"]='create';
|
$_GET['action']='create';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -187,49 +180,43 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Ref")).'</div>';
|
$mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('Ref')).'</div>';
|
||||||
$_GET["action"]='create';
|
$_GET['action']='create';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["action"] == 'del_ligne')
|
if ($_GET['action'] == 'del_ligne')
|
||||||
{
|
{
|
||||||
$facfou = new FactureFournisseur($db,"",$_GET["facid"]);
|
$facfou = new FactureFournisseur($db,'',$_GET['facid']);
|
||||||
|
$facfou->deleteline($_GET['ligne_id']);
|
||||||
$facfou->deleteline($_GET["ligne_id"]);
|
$_GET['action'] = 'edit';
|
||||||
|
|
||||||
$_GET["action"] = "edit";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET['action'] == 'add_ligne')
|
if ($_GET['action'] == 'add_ligne')
|
||||||
{
|
{
|
||||||
$facfou = new FactureFournisseur($db, '', $_GET['facid']);
|
$facfou = new FactureFournisseur($db, '', $_GET['facid']);
|
||||||
|
$tauxtva = price2num($_POST['tauxtva']);
|
||||||
if (strlen($_POST['label']) > 0 && !empty($_POST['amount']))
|
if (strlen($_POST['label']) > 0 && !empty($_POST['amount']))
|
||||||
{
|
{
|
||||||
$ht = $_POST['amount'];
|
$ht = price2num($_POST['amount']);
|
||||||
$ht = str_replace(' ', '', $ht);
|
$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']);
|
||||||
$ht = str_replace(',', '.', $ht);
|
|
||||||
$facfou->addline($_POST['label'], $ht, $_POST['tauxtva'], $_POST['qty']);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$ttc = $_POST['amountttc'];
|
$ttc = price2num($_POST['amountttc']);
|
||||||
$ttc = str_replace(' ', '', $ttc);
|
$ht = $ttc / (1 + ($tauxtva / 100));
|
||||||
$ttc = str_replace(',', '.', $ttc);
|
$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']);
|
||||||
$ht = $ttc / (1 + ($_POST['tauxtva'] / 100));
|
|
||||||
$facfou->addline($_POST['label'], $ht, $_POST['tauxtva'], $_POST['qty']);
|
|
||||||
}
|
}
|
||||||
$_GET['action'] = 'edit';
|
$_GET['action'] = 'edit';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*********************************************************************
|
||||||
*
|
*
|
||||||
* Fiche facture en mode creation
|
* Mode creation
|
||||||
*
|
*
|
||||||
*/
|
**********************************************************************/
|
||||||
|
|
||||||
if ($_GET['action'] == 'create' or $_GET['action'] == 'copy')
|
if ($_GET['action'] == 'create' or $_GET['action'] == 'copy')
|
||||||
{
|
{
|
||||||
@ -247,46 +234,11 @@ if ($_GET['action'] == 'create' or $_GET['action'] == 'copy')
|
|||||||
|
|
||||||
print '<form action="fiche.php" method="post">';
|
print '<form action="fiche.php" method="post">';
|
||||||
print '<input type="hidden" name="action" value="add">';
|
print '<input type="hidden" name="action" value="add">';
|
||||||
|
|
||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
print '<tr><td>'.$langs->trans('Company').'</td>';
|
print '<tr><td>'.$langs->trans('Company').'</td>';
|
||||||
|
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$html->select_societes(empty($_GET['socid'])?'':$_GET['socid'],'socidp','s.fournisseur = 1');
|
$html->select_societes(empty($_GET['socid'])?'':$_GET['socid'],'socidp','s.fournisseur = 1');
|
||||||
/*
|
|
||||||
print '<td><select name="socidp">';
|
|
||||||
|
|
||||||
$sql = 'SELECT s.nom, s.prefix_comm, s.idp';
|
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
|
||||||
$sql .= ' WHERE s.fournisseur = 1';
|
|
||||||
if ($_GET['socid'] > 0 )
|
|
||||||
{
|
|
||||||
$sql .= ' AND s.idp ='.$_GET['socid'];
|
|
||||||
}
|
|
||||||
$sql .= ' ORDER BY s.nom ASC';
|
|
||||||
|
|
||||||
if ( $db->query($sql) )
|
|
||||||
{
|
|
||||||
$num = $db->num_rows();
|
|
||||||
$i = 0;
|
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object();
|
|
||||||
print '<option value="'.$obj->idp;
|
|
||||||
|
|
||||||
if ($_GET['socid'] == $obj->idp)
|
|
||||||
{
|
|
||||||
print '" selected="true">'.$obj->nom.'</option>';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print '">'.$obj->nom.'</option>';
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print '</select></td>';
|
|
||||||
*/
|
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td width="50%">'.$langs->trans('Comments').'</td></tr>';
|
print '<td width="50%">'.$langs->trans('Comments').'</td></tr>';
|
||||||
|
|
||||||
@ -348,15 +300,16 @@ if ($_GET['action'] == 'create' or $_GET['action'] == 'copy')
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
if ($_GET['facid'] > 0)
|
||||||
* Fiche facture en mode visu ou edition
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if ($_GET["facid"] > 0)
|
|
||||||
{
|
{
|
||||||
|
/* *************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* Fiche en mode visu ou edition */
|
||||||
|
/* */
|
||||||
|
/* *************************************************************************** */
|
||||||
|
|
||||||
$fac = new FactureFournisseur($db);
|
$fac = new FactureFournisseur($db);
|
||||||
$fac->fetch($_GET["facid"]);
|
$fac->fetch($_GET['facid']);
|
||||||
|
|
||||||
$societe = new Fournisseur($db);
|
$societe = new Fournisseur($db);
|
||||||
|
|
||||||
@ -367,23 +320,23 @@ else
|
|||||||
}
|
}
|
||||||
llxHeader('','', $addons);
|
llxHeader('','', $addons);
|
||||||
|
|
||||||
if ($mesg) { print "<br>$mesg<br>"; }
|
if ($mesg) { print '<br>'.$mesg.'<br>'; }
|
||||||
|
|
||||||
if ($_GET["action"] == "edit")
|
if ($_GET['action'] == 'edit')
|
||||||
{
|
{
|
||||||
|
|
||||||
print_titre($langs->trans("Bill").': '.$fac->ref);
|
print_titre($langs->trans('Bill').': '.$fac->ref);
|
||||||
|
|
||||||
print '<form action="fiche.php?facid='.$fac->id.'" method="post">';
|
print '<form action="fiche.php?facid='.$fac->id.'" method="post">';
|
||||||
print '<input type="hidden" name="action" value="update">';
|
print '<input type="hidden" name="action" value="update">';
|
||||||
|
|
||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
print '<tr><td>'.$langs->trans("Company").'</td>';
|
print '<tr><td>'.$langs->trans('Company').'</td>';
|
||||||
|
|
||||||
print '<td>'.stripslashes($fac->socnom).'</td>';
|
print '<td>'.stripslashes($fac->socnom).'</td>';
|
||||||
print '<td width="50%" valign="top">'.$langs->trans("Comments").'</tr>';
|
print '<td width="50%" valign="top">'.$langs->trans('Comments').'</tr>';
|
||||||
|
|
||||||
print '<tr><td valign="top">'.$langs->trans("Ref").'</td><td valign="top">';
|
print '<tr><td valign="top">'.$langs->trans('Ref').'</td><td valign="top">';
|
||||||
print '<input name="facnumber" type="text" value="'.$fac->ref.'"></td>';
|
print '<input name="facnumber" type="text" value="'.$fac->ref.'"></td>';
|
||||||
|
|
||||||
print '<td rowspan="8" valign="top">';
|
print '<td rowspan="8" valign="top">';
|
||||||
@ -391,32 +344,32 @@ else
|
|||||||
print stripslashes($fac->note);
|
print stripslashes($fac->note);
|
||||||
print '</textarea></td></tr>';
|
print '</textarea></td></tr>';
|
||||||
|
|
||||||
print '<tr><td valign="top">'.$langs->trans("Label").'</td><td>';
|
print '<tr><td valign="top">'.$langs->trans('Label').'</td><td>';
|
||||||
print '<input size="30" name="libelle" type="text" value="'.stripslashes($fac->libelle).'"></td></tr>';
|
print '<input size="30" name="libelle" type="text" value="'.stripslashes($fac->libelle).'"></td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("AmountHT").' / '.$langs->trans("AmountTTC").'</td>';
|
print '<tr><td>'.$langs->trans('AmountHT').' / '.$langs->trans('AmountTTC').'</td>';
|
||||||
print '<td>'.price($fac->total_ht).' / '.price($fac->total_ttc).'</td></tr>';
|
print '<td>'.price($fac->total_ht).' / '.price($fac->total_ttc).'</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("DateBill").'</td><td>';
|
print '<tr><td>'.$langs->trans('DateBill').'</td><td>';
|
||||||
$html->select_date($fac->datep);
|
$html->select_date($fac->datep);
|
||||||
print "</td></tr>";
|
print '</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("DateEcheance").'</td><td>';
|
print '<tr><td>'.$langs->trans('DateEcheance').'</td><td>';
|
||||||
$html->select_date($fac->date_echeance,'ech');
|
$html->select_date($fac->date_echeance,'ech');
|
||||||
print "</td></tr>";
|
print '</td></tr>';
|
||||||
|
|
||||||
$authorfullname=" ";
|
$authorfullname=' ';
|
||||||
if ($fac->author)
|
if ($fac->author)
|
||||||
{
|
{
|
||||||
$author = new User($db, $fac->author);
|
$author = new User($db, $fac->author);
|
||||||
$author->fetch('');
|
$author->fetch('');
|
||||||
$authorfullname=$author->fullname;
|
$authorfullname=$author->fullname;
|
||||||
}
|
}
|
||||||
print "<tr><td>".$langs->trans("Author")."</td><td>$authorfullname</td></tr>";
|
print '<tr><td>'.$langs->trans('Author').'</td><td>'.$authorfullname.'</td></tr>';
|
||||||
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$fac->LibStatut($fac->paye,$fac->statut)."</td></tr>";
|
print '<tr><td>'.$langs->trans('Status').'</td><td>'.$fac->LibStatut($fac->paye,$fac->statut).'</td></tr>';
|
||||||
print "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" class=\"button\" value=\"".$langs->trans("Save")."\"></td></tr>";
|
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans('Save').'"></td></tr>';
|
||||||
print "</table>";
|
print '</table>';
|
||||||
print "</form>";
|
print '</form>';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lignes
|
* Lignes
|
||||||
@ -425,27 +378,27 @@ else
|
|||||||
print '<br>';
|
print '<br>';
|
||||||
$var=true;
|
$var=true;
|
||||||
|
|
||||||
print "<form action=\"fiche.php?facid=$fac->id&action=add_ligne\" method=\"post\">";
|
print '<form action="fiche.php?facid='.$fac->id.'&action=add_ligne" method="post">';
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre"><td>'.$langs->trans("Label").'</td>';
|
print '<tr class="liste_titre"><td>'.$langs->trans('Label').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("PriceUHT").'</td>';
|
print '<td align="center">'.$langs->trans('PriceUHT').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("PriceUTTC").'</td>';
|
print '<td align="center">'.$langs->trans('PriceUTTC').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("Qty").'</td>';
|
print '<td align="center">'.$langs->trans('Qty').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("TotalHT").'</td>';
|
print '<td align="center">'.$langs->trans('TotalHT').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("VATRate").'</td>';
|
print '<td align="center">'.$langs->trans('VATRate').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("VAT").'</td>';
|
print '<td align="center">'.$langs->trans('VAT').'</td>';
|
||||||
print '<td align="right">'.$langs->trans("TotalTTC").'</td><td> </td></tr>';
|
print '<td align="right">'.$langs->trans('TotalTTC').'</td><td> </td></tr>';
|
||||||
for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++)
|
for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++)
|
||||||
{
|
{
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
print "<tr $bc[$var]>".'<td>'.$fac->lignes[$i][0]."</td>";
|
print '<tr '.$bc[$var].'><td>'.$fac->lignes[$i][0].'</td>';
|
||||||
print '<td align="center">'.price($fac->lignes[$i][1])."</td>";
|
print '<td align="center">'.price($fac->lignes[$i][1]).'</td>';
|
||||||
print '<td align="center">'.price($fac->lignes[$i][1] * (1+($fac->lignes[$i][2]/100)))."</td>";
|
print '<td align="center">'.price($fac->lignes[$i][1] * (1+($fac->lignes[$i][2]/100))).'</td>';
|
||||||
print '<td align="center">'.$fac->lignes[$i][3]."</td>";
|
print '<td align="center">'.$fac->lignes[$i][3].'</td>';
|
||||||
print '<td align="center">'.price($fac->lignes[$i][4])."</td>";
|
print '<td align="center">'.price($fac->lignes[$i][4]).'</td>';
|
||||||
print '<td align="center">'.$fac->lignes[$i][2]."</td>";
|
print '<td align="center">'.$fac->lignes[$i][2].'</td>';
|
||||||
print '<td align="center">'.price($fac->lignes[$i][5])."</td>";
|
print '<td align="center">'.price($fac->lignes[$i][5]).'</td>';
|
||||||
print '<td align="right">'.price($fac->lignes[$i][6])."</td>";
|
print '<td align="right">'.price($fac->lignes[$i][6]).'</td>';
|
||||||
print '<td align="center">';
|
print '<td align="center">';
|
||||||
print '<a href="fiche.php?facid='.$fac->id.'&action=del_ligne&ligne_id='.$fac->lignes[$i][7].'">'.img_delete().'</a></td>';
|
print '<a href="fiche.php?facid='.$fac->id.'&action=del_ligne&ligne_id='.$fac->lignes[$i][7].'">'.img_delete().'</a></td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
@ -453,7 +406,7 @@ else
|
|||||||
|
|
||||||
/* Nouvelle ligne */
|
/* Nouvelle ligne */
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
print "<tr $bc[$var]>";
|
print '<tr '.$bc[$var].'>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print '<input size="30" name="label" type="text">';
|
print '<input size="30" name="label" type="text">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
@ -468,27 +421,26 @@ else
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td align="center">-</td>';
|
print '<td align="center">-</td>';
|
||||||
print '<td align="center">';
|
print '<td align="center">';
|
||||||
$html->select_tva("tauxtva");
|
$html->select_tva('tauxtva');
|
||||||
print '</td><td align="center" colspan="2">';
|
print '</td><td align="center" colspan="2">';
|
||||||
print ' ';
|
print ' ';
|
||||||
print '</td><td align="center"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
|
print '</td><td align="center"><input type="submit" class="button" value="'.$langs->trans('Add').'"></td></tr>';
|
||||||
print "</table>";
|
print '</table>';
|
||||||
print "</form>";
|
print '</form>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$h=0;
|
$h=0;
|
||||||
|
|
||||||
$head[$h][0] = "fiche.php?facid=".$fac->id;
|
$head[$h][0] = 'fiche.php?facid='.$fac->id;
|
||||||
$head[$h][1] = $langs->trans("Card");
|
$head[$h][1] = $langs->trans('Card');
|
||||||
$hselected = $h;
|
$hselected = $h;
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
$titre=$langs->trans("SupplierBill").': '.$fac->ref;
|
$titre=$langs->trans('SupplierBill').': '.$fac->ref;
|
||||||
dolibarr_fiche_head($head, $hselected, $titre);
|
dolibarr_fiche_head($head, $hselected, $titre);
|
||||||
|
|
||||||
|
|
||||||
@ -515,39 +467,39 @@ else
|
|||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
// Societe
|
// Societe
|
||||||
print "<tr><td>".$langs->trans("Company")."</td><td colspan=\"2\"><a href=\"../fiche.php?socid=$fac->socidp\">".dolibarr_trunc($fac->socnom,24)."</td>";
|
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2"><a href="../fiche.php?socid='.$fac->socidp.'">'.dolibarr_trunc($fac->socnom,24).'</a></td>';
|
||||||
print "<td align=\"right\"><a href=\"index.php?socid=$fac->socidp\">".$langs->trans("OtherBills")."</a></td>";
|
print '<td align="right"><a href="index.php?socid='.$fac->socidp.'">'.$langs->trans('OtherBills').'</a></td>';
|
||||||
print "</tr>\n";
|
print '</tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("Date")."</td><td colspan=\"3\">";
|
print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">';
|
||||||
print dolibarr_print_date($fac->datep,"%A %d %B %Y")."</td></tr>\n";
|
print dolibarr_print_date($fac->datep,'%A %d %B %Y').'</td></tr>';
|
||||||
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">';
|
print '<tr><td>'.$langs->trans('Label').'</td><td colspan="3">';
|
||||||
print $fac->libelle;
|
print $fac->libelle;
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
$authorfullname=" ";
|
$authorfullname=' ';
|
||||||
if ($fac->author)
|
if ($fac->author)
|
||||||
{
|
{
|
||||||
$author = new User($db, $fac->author);
|
$author = new User($db, $fac->author);
|
||||||
$author->fetch('');
|
$author->fetch('');
|
||||||
$authorfullname=$author->fullname;
|
$authorfullname=$author->fullname;
|
||||||
}
|
}
|
||||||
print "<tr><td>".$langs->trans("Author")."</td><td colspan=\"3\">$authorfullname</td>";
|
print '<tr><td>'.$langs->trans('Author').'</td><td colspan="3">'.$authorfullname.'</td>';
|
||||||
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$fac->LibStatut($fac->paye,$fac->statut)."</td></tr>";
|
print '<tr><td>'.$langs->trans('Status').'</td><td colspan="3">'.$fac->LibStatut($fac->paye,$fac->statut).'</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("AmountHT").'</td><td><b>'.price($fac->total_ht).'</b></td><td colspan="2" align="left">'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
print '<tr><td>'.$langs->trans('AmountHT').'</td><td><b>'.price($fac->total_ht).'</b></td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
||||||
print '<tr><td>'.$langs->trans("AmountVAT").'</td><td>'.price($fac->total_tva).'</td><td colspan="2" align="left">'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($fac->total_tva).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
||||||
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($fac->total_ttc).'</td><td colspan="2" align="left">'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($fac->total_ttc).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
||||||
if (strlen($fac->note))
|
if (strlen($fac->note))
|
||||||
{
|
{
|
||||||
print '<tr><td>'.$langs->trans("Comments").'</td><td colspan="3">';
|
print '<tr><td>'.$langs->trans('Comments').'</td><td colspan="3">';
|
||||||
print nl2br(stripslashes($fac->note));
|
print nl2br(stripslashes($fac->note));
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
print "</table>";
|
print '</table>';
|
||||||
|
|
||||||
print "</td><td valign=\"top\">";
|
print '</td><td valign="top">';
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -557,14 +509,18 @@ else
|
|||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
|
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>'.$langs->trans("DateEcheance").'</td><td>';
|
print '<td>'.$langs->trans('DateEcheance').'</td><td>';
|
||||||
print dolibarr_print_date($fac->date_echeance,"%A %d %B %Y")."</td></tr>\n";
|
print dolibarr_print_date($fac->date_echeance,'%A %d %B %Y').'</td></tr>';
|
||||||
|
|
||||||
print '<tr><td colspan="2">'.$langs->trans("Payments").'</td></tr>';
|
print '<tr><td colspan="2">'.$langs->trans('Payments').'</td></tr>';
|
||||||
|
|
||||||
$sql = "SELECT ".$db->pdate("datep")." as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid";
|
$sql = 'SELECT '.$db->pdate('datep').' as dp, pf.amount,';
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p, ".MAIN_DB_PREFIX."c_paiement as c ";
|
$sql .= ' c.libelle as paiement_type, p.num_paiement, p.rowid';
|
||||||
$sql .= " WHERE p.fk_facture_fourn = ".$fac->id." AND p.fk_paiement = c.id";
|
$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);
|
$result = $db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
@ -575,26 +531,25 @@ else
|
|||||||
print '<tr><td colspan="2">';
|
print '<tr><td colspan="2">';
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
|
|
||||||
print "<tr class=\"liste_titre\">";
|
print '<tr class="liste_titre">';
|
||||||
print '<td>'.$langs->trans("Date").'</td>';
|
print '<td>'.$langs->trans('Date').'</td>';
|
||||||
print '<td>'.$langs->trans("Type").'</td>';
|
print '<td>'.$langs->trans('Type').'</td>';
|
||||||
|
|
||||||
if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
|
if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
|
||||||
{
|
{
|
||||||
$tdsup=' colspan="2"';
|
$tdsup=' colspan="2"';
|
||||||
}
|
}
|
||||||
print "<td align=\"right\">".$langs->trans("AmountTTC")."</td><td$tdsup> </td>";
|
print '<td align="right">'.$langs->trans('AmountTTC').'</td><td'.$tdsup.'> </td></tr>';
|
||||||
print "</tr>\n";
|
|
||||||
|
|
||||||
$var=True;
|
$var=True;
|
||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$objp = $db->fetch_object($result);
|
$objp = $db->fetch_object($result);
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
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("Payment"),"payment").'</a> '.dolibarr_print_date($objp->dp)."</td>\n";
|
print '<td nowrap><a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans('Payment'),'payment').'</a> '.dolibarr_print_date($objp->dp)."</td>\n";
|
||||||
print "<td>$objp->paiement_type $objp->num_paiement</td>\n";
|
print '<td>'.$objp->paiement_type.' '.$objp->num_paiement.'</td>';
|
||||||
print "<td align=\"right\">".price($objp->amount)."</td><td>".$langs->trans("Currency".$conf->monnaie)."</td>\n";
|
print '<td align="right">'.price($objp->amount).'</td><td>'.$langs->trans('Currency'.$conf->monnaie).'</td>';
|
||||||
|
|
||||||
if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
|
if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
|
||||||
{
|
{
|
||||||
@ -604,35 +559,35 @@ else
|
|||||||
print '</a></td>';
|
print '</a></td>';
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</tr>";
|
print '</tr>';
|
||||||
$total = $total + $objp->amount;
|
$total = $total + $objp->amount;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
print "<tr class=\"liste_total\"><td colspan=\"2\" align=\"right\">".$langs->trans("Total")." :</td><td align=\"right\"><b>".price($total)."</b></td><td$tdsup>".$langs->trans("Currency".$conf->monnaie)."</td></tr>\n";
|
print '<tr class="liste_total"><td colspan="2" align="right">'.$langs->trans('Total').' :</td><td align="right"><b>'.price($total).'</b></td><td'.$tdsup.'>'.$langs->trans('Currency'.$conf->monnaie)."</td></tr>\n";
|
||||||
|
|
||||||
|
|
||||||
if ($fac->statut > 0)
|
if ($fac->statut > 0)
|
||||||
{
|
{
|
||||||
$resteapayer = abs($fac->total_ttc - $total);
|
$resteapayer = abs($fac->total_ttc - $total);
|
||||||
print "<tr class=\liste_total\"><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
|
print '<tr class="liste_total"><td colspan="2" align="right">'.$langs->trans('RemainderToPay').' :</td>';
|
||||||
print '<td align="right"><b>'.price($resteapayer)."</b></td><td$tdsup>".$langs->trans("Currency".$conf->monnaie)."</td>";
|
print '<td align="right"><b>'.price($resteapayer).'</b></td><td'.$tdsup.'>'.$langs->trans('Currency'.$conf->monnaie).'</td>';
|
||||||
print "</tr>\n";
|
print '</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</table>";
|
print '</table>';
|
||||||
$db->free();
|
$db->free();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($db);
|
dolibarr_print_error($db);
|
||||||
}
|
}
|
||||||
print "</td></tr>";
|
print '</td></tr>';
|
||||||
print "</table>";
|
print '</table>';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print "</td></tr>";
|
print '</td></tr>';
|
||||||
print "</table>";
|
print '</table>';
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -641,30 +596,28 @@ else
|
|||||||
*/
|
*/
|
||||||
print '<br>';
|
print '<br>';
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre"><td>'.$langs->trans("Label").'</td>';
|
print '<tr class="liste_titre"><td>'.$langs->trans('Label').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("PriceUHT").'</td>';
|
print '<td align="center">'.$langs->trans('PriceUHT').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("Qty").'</td>';
|
print '<td align="center">'.$langs->trans('Qty').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("TotalHT").'</td>';
|
print '<td align="center">'.$langs->trans('TotalHT').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("VATRate").'</td>';
|
print '<td align="center">'.$langs->trans('VATRate').'</td>';
|
||||||
print '<td align="center">'.$langs->trans("VAT").'</td>';
|
print '<td align="center">'.$langs->trans('VAT').'</td>';
|
||||||
print '<td align="right">'.$langs->trans("TotalTTC").'</td></tr>';
|
print '<td align="right">'.$langs->trans('TotalTTC').'</td></tr>';
|
||||||
$var=1;
|
$var=1;
|
||||||
for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++)
|
for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++)
|
||||||
{
|
{
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
print "<tr $bc[$var]>".'<td>'.$fac->lignes[$i][0]."</td>";
|
print '<tr '.$bc[$var].'><td>'.$fac->lignes[$i][0].'</td>';
|
||||||
print '<td align="center">'.price($fac->lignes[$i][1])."</td>";
|
print '<td align="center">'.price($fac->lignes[$i][1]).'</td>';
|
||||||
print '<td align="center">'.$fac->lignes[$i][3]."</td>";
|
print '<td align="center">'.$fac->lignes[$i][3].'</td>';
|
||||||
print '<td align="center">'.price($fac->lignes[$i][4])."</td>";
|
print '<td align="center">'.price($fac->lignes[$i][4]).'</td>';
|
||||||
print '<td align="center">'.$fac->lignes[$i][2]." %</td>";
|
print '<td align="center">'.$fac->lignes[$i][2].' %</td>';
|
||||||
print '<td align="center">'.price($fac->lignes[$i][5])."</td>";
|
print '<td align="center">'.price($fac->lignes[$i][5]).'</td>';
|
||||||
print '<td align="right">'.price($fac->lignes[$i][6])."</td>";
|
print '<td align="right">'.price($fac->lignes[$i][6]).'</td>';
|
||||||
|
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
print "</table>";
|
print '</table>';
|
||||||
|
print '</div>';
|
||||||
print "</div>\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -672,13 +625,13 @@ else
|
|||||||
* Boutons actions
|
* Boutons actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
print "<div class=\"tabsAction\">\n";
|
print '<div class="tabsAction">';
|
||||||
|
|
||||||
if ($fac->statut == 0 && $user->societe_id == 0)
|
if ($fac->statut == 0 && $user->societe_id == 0)
|
||||||
{
|
{
|
||||||
if ($_GET["action"] == "edit")
|
if ($_GET['action'] == 'edit')
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="fiche.php?facid='.$fac->id.'">'.$langs->trans("Cancel").'</a>';
|
print '<a class="butAction" href="fiche.php?facid='.$fac->id.'">'.$langs->trans('Cancel').'</a>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -688,33 +641,30 @@ else
|
|||||||
|
|
||||||
if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
|
if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="paiement.php?facid='.$fac->id.'&action=create">'.$langs->trans("DoPaiement").'</a>';
|
print '<a class="butAction" href="paiement.php?facid='.$fac->id.'&action=create">'.$langs->trans('DoPaiement').'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fac->statut == 1 && price($resteapayer) <= 0 && $fac->paye == 0 && $user->societe_id == 0)
|
if ($fac->statut == 1 && price($resteapayer) <= 0 && $fac->paye == 0 && $user->societe_id == 0)
|
||||||
{
|
{
|
||||||
print "<a class=\"butAction\" href=\"fiche.php?facid=$fac->id&action=payed\">".$langs->trans('ClassifyPayed')."</a>";
|
print '<a class="butAction" href="fiche.php?facid='.$fac->id.'&action=payed">'.$langs->trans('ClassifyPayed').'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fac->statut == 0 && $user->rights->fournisseur->facture->valider)
|
if ($fac->statut == 0 && $user->rights->fournisseur->facture->valider)
|
||||||
{
|
{
|
||||||
if ($_GET["action"] <> "edit")
|
if ($_GET['action'] <> 'edit')
|
||||||
print "<a class=\"butAction\" href=\"fiche.php?facid=$fac->id&action=valid\">".$langs->trans('Valid')."</a>";
|
print '<a class="butAction" href="fiche.php?facid='.$fac->id.'&action=valid">'.$langs->trans('Valid').'</a>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
||||||
if ($user->rights->fournisseur->facture->creer)
|
if ($user->rights->fournisseur->facture->creer)
|
||||||
{
|
{
|
||||||
print "<a class=\"butAction\" href=\"fiche.php?facid=$fac->id&action=copy&socid=$fac->socidp\">".$langs->trans('Copy')."</a>";
|
print '<a class="butAction" href="fiche.php?facid='.$fac->id.'&action=copy&socid='.$fac->socidp.'">'.$langs->trans('Copy').'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["action"] != "edit" && $fac->statut == 0 && $user->rights->fournisseur->facture->creer)
|
if ($_GET['action'] != 'edit' && $fac->statut == 0 && $user->rights->fournisseur->facture->creer)
|
||||||
{
|
{
|
||||||
print '<a class="butActionDelete" href="index.php?facid='.$fac->id.'&action=delete">'.$langs->trans("Delete").'</a>';
|
print '<a class="butActionDelete" href="index.php?facid='.$fac->id.'&action=delete">'.$langs->trans('Delete').'</a>';
|
||||||
}
|
}
|
||||||
|
print '</div>';
|
||||||
print "</div>";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
* Copyright (C) 2004 Éric Seigne <eric.seigne@ryxeo.com>
|
* Copyright (C) 2004 Éric Seigne <eric.seigne@ryxeo.com>
|
||||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
|
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
|
||||||
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -31,19 +32,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require('./pre.inc.php');
|
||||||
require("./paiementfourn.class.php");
|
require('./paiementfourn.class.php');
|
||||||
|
|
||||||
$langs->load("bills");
|
$langs->load('bills');
|
||||||
$langs->load("banks");
|
$langs->load('banks');
|
||||||
|
|
||||||
|
$facid=isset($_GET['facid'])?$_GET['facid']:$_POST['facid'];
|
||||||
|
$action=isset($_GET['action'])?$_GET['action']:$_POST['action'];
|
||||||
|
|
||||||
$facid=isset($_GET["facid"])?$_GET["facid"]:$_POST["facid"];
|
$sortfield = isset($_GET['sortfield'])?$_GET['sortfield']:$_POST['sortfield'];
|
||||||
$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
|
$sortorder = isset($_GET['sortorder'])?$_GET['sortorder']:$_POST['sortorder'];
|
||||||
|
$page=isset($_GET['page'])?$_GET['page']:$_POST['page'];
|
||||||
$page=$_GET["page"];
|
|
||||||
$sortorder=$_GET["sortorder"];
|
|
||||||
$sortfield=$_GET["sortfield"];
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -55,145 +55,284 @@ if ($user->societe_id > 0)
|
|||||||
$socidp = $user->societe_id;
|
$socidp = $user->societe_id;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
*
|
* Actions
|
||||||
*/
|
*/
|
||||||
if ($action == 'add') {
|
if ($action == 'add_paiement')
|
||||||
$paiementfourn = new PaiementFourn($db);
|
|
||||||
|
|
||||||
$paiementfourn->facid = $facid;
|
|
||||||
$paiementfourn->facnumber = $_POST['facnumber'];
|
|
||||||
$paiementfourn->datepaye = $db->idate(mktime(12, 0 , 0,
|
|
||||||
$_POST["remonth"],
|
|
||||||
$_POST["reday"],
|
|
||||||
$_POST["reyear"]));
|
|
||||||
$paiementfourn->amount = $_POST['amount'];
|
|
||||||
$paiementfourn->accountid = $_POST['accountid'];
|
|
||||||
$paiementfourn->societe = $_POST['societe'];
|
|
||||||
$paiementfourn->paiementid = $_POST['paiementid'];
|
|
||||||
$paiementfourn->num_paiement = $_POST['num_paiement'];
|
|
||||||
$paiementfourn->note = $_POST['note'];
|
|
||||||
|
|
||||||
if ( $paiementfourn->create($user) )
|
|
||||||
{
|
{
|
||||||
Header("Location: fiche.php?facid=$facid");
|
$error = 0;
|
||||||
|
|
||||||
|
$datepaye = $db->idate(mktime(12, 0 , 0,
|
||||||
|
$_POST['remonth'],
|
||||||
|
$_POST['reday'],
|
||||||
|
$_POST['reyear']));
|
||||||
|
$paiement_id = 0;
|
||||||
|
$total = 0;
|
||||||
|
// Génère tableau des montants amounts
|
||||||
|
$amounts = array();
|
||||||
|
foreach ($_POST as $key => $value)
|
||||||
|
{
|
||||||
|
if (substr($key,0,7) == 'amount_')
|
||||||
|
{
|
||||||
|
$other_facid = substr($key,7);
|
||||||
|
$amounts[$other_facid] = $_POST[$key];
|
||||||
|
$total = $total + $amounts[$other_facid];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = '';
|
// Effectue les vérifications des parametres
|
||||||
|
if ($_POST['paiementid'] <= 0)
|
||||||
|
{
|
||||||
|
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('PaymentMode')).'</div>';
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($conf->banque->enabled)
|
||||||
|
{
|
||||||
|
// Si module bank actif, un compte est obligatoire lors de la saisie
|
||||||
|
// d'un paiement
|
||||||
|
if (! $_POST['accountid'])
|
||||||
|
{
|
||||||
|
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('AccountToCredit')).'</div>';
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($total <= 0)
|
||||||
|
{
|
||||||
|
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('Amount')).'</div>';
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
// Creation de la ligne paiement
|
||||||
|
$paiement = new PaiementFourn($db);
|
||||||
|
$paiement->datepaye = $datepaye;
|
||||||
|
$paiement->amounts = $amounts; // Tableau de montant
|
||||||
|
$paiement->paiementid = $_POST['paiementid'];
|
||||||
|
$paiement->num_paiement = $_POST['num_paiement'];
|
||||||
|
$paiement->note = $_POST['comment'];
|
||||||
|
|
||||||
|
$paiement_id = $paiement->create($user);
|
||||||
|
if ($paiement_id > 0)
|
||||||
|
{
|
||||||
|
if ($conf->banque->enabled)
|
||||||
|
{
|
||||||
|
// Insertion dans llx_bank
|
||||||
|
$label = 'Règlement fournisseur';
|
||||||
|
$acc = new Account($db, $_POST['accountid']);
|
||||||
|
//paiementid contient "CHQ ou VIR par exemple"
|
||||||
|
$bank_line_id = $acc->addline($paiement->datepaye,
|
||||||
|
$paiement->paiementid,
|
||||||
|
$label,
|
||||||
|
0.0 - $paiement->total,
|
||||||
|
$paiement->num_paiement,
|
||||||
|
'',
|
||||||
|
$user);
|
||||||
|
|
||||||
|
// Mise a jour fk_bank dans llx_paiement.
|
||||||
|
// On connait ainsi le paiement qui a généré l'écriture bancaire
|
||||||
|
if ($bank_line_id > 0)
|
||||||
|
{
|
||||||
|
$paiement->update_fk_bank($bank_line_id);
|
||||||
|
// Mise a jour liens (pour chaque facture concernées par le paiement)
|
||||||
|
foreach ($paiement->amounts as $key => $value)
|
||||||
|
{
|
||||||
|
$facid = $key;
|
||||||
|
$fac = new FactureFournisseur($db);
|
||||||
|
$fac->fetch($facid);
|
||||||
|
$fac->fetch_fournisseur();
|
||||||
|
$acc->add_url_line($bank_line_id,
|
||||||
|
$paiement_id,
|
||||||
|
DOL_URL_ROOT.'/fourn/paiement/fiche.php?id=',
|
||||||
|
'(paiement)',
|
||||||
|
'payment');
|
||||||
|
$acc->add_url_line($bank_line_id,
|
||||||
|
$fac->fournisseur->id,
|
||||||
|
DOL_URL_ROOT.'/fourn/fiche.php?socid=',
|
||||||
|
$fac->fournisseur->nom,
|
||||||
|
'company');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$paiement->error;
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error == 0)
|
||||||
|
{
|
||||||
|
$loc = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement_id;
|
||||||
|
$db->commit();
|
||||||
|
Header('Location: '.$loc);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$db->rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
* Affichage
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
llxHeader();
|
llxHeader();
|
||||||
|
|
||||||
if ($action == 'create')
|
|
||||||
{
|
|
||||||
|
|
||||||
$sql = "SELECT s.nom,s.idp, f.amount, f.total_ttc, f.facnumber";
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as f WHERE f.fk_soc = s.idp";
|
|
||||||
$sql .= " AND f.rowid = $facid";
|
|
||||||
|
|
||||||
$result = $db->query($sql);
|
|
||||||
if ($result)
|
|
||||||
{
|
|
||||||
$num = $db->num_rows();
|
|
||||||
if ($num)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($result);
|
|
||||||
|
|
||||||
$total = $obj->total_ttc;
|
|
||||||
|
|
||||||
print_titre($langs->trans("DoPayment"));
|
|
||||||
print '<form action="paiement.php?facid='.$facid.'" method="post">';
|
|
||||||
print '<input type="hidden" name="action" value="add">';
|
|
||||||
print '<table class="border" width="100%">';
|
|
||||||
|
|
||||||
print "<tr class=\"liste_titre\"><td colspan=\"3\">".$langs->trans("Bill")."</td>";
|
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("Ref").' :</td><td colspan="2">';
|
|
||||||
print '<a href="fiche.php?facid='.$facid.'">'.$obj->facnumber.'</a></td></tr>';
|
|
||||||
print "<tr><td>".$langs->trans("Company")." :</td><td colspan=\"2\">$obj->nom</td></tr>";
|
|
||||||
|
|
||||||
print "<tr><td>".$langs->trans("AmountTTC")." :</td><td colspan=\"2\">".price($obj->total_ttc).' '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
|
||||||
|
|
||||||
$sql = "SELECT sum(p.amount) FROM ".MAIN_DB_PREFIX."paiementfourn as p WHERE p.fk_facture_fourn = $facid;";
|
|
||||||
$result = $db->query($sql);
|
|
||||||
if ($result) {
|
|
||||||
$sumpayed = $db->result(0,0);
|
|
||||||
$db->free();
|
|
||||||
}
|
|
||||||
print '<tr><td>'.$langs->trans("AlreadyPayed").' :</td><td colspan="2"><b>'.price($sumpayed).'</b> '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
|
||||||
|
|
||||||
print "<tr class=\"liste_titre\"><td colspan=\"3\">".$langs->trans("Payment")."</td>";
|
|
||||||
|
|
||||||
print "<input type=\"hidden\" name=\"facid\" value=\"$facid\">";
|
|
||||||
print "<input type=\"hidden\" name=\"facnumber\" value=\"$obj->facnumber\">";
|
|
||||||
print "<input type=\"hidden\" name=\"socid\" value=\"$obj->idp\">";
|
|
||||||
print "<input type=\"hidden\" name=\"societe\" value=\"$obj->nom\">";
|
|
||||||
|
|
||||||
$html=new Form($db);
|
$html=new Form($db);
|
||||||
|
|
||||||
print "<tr><td>".$langs->trans("Date")." :</td><td>";
|
if ($fiche_erreur_message)
|
||||||
$html->select_date();
|
{
|
||||||
print "</td>";
|
print '<tr><td colspan="3" align="center">'.$fiche_erreur_message.'</td></tr>';
|
||||||
|
}
|
||||||
print '<td>'.$langs->trans("Comments").' :</td></tr>';
|
|
||||||
|
if ($action == 'create' || $action == 'add_paiement')
|
||||||
print '<tr><td>'.$langs->trans("Type").' :</td>';
|
{
|
||||||
print '<td><select name="paiementid">';
|
$facture = new FactureFournisseur($db);
|
||||||
|
$facture->fetch($facid);
|
||||||
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement ORDER BY id";
|
|
||||||
|
$sql = 'SELECT s.nom,s.idp, f.amount, f.total_ttc as total, f.facnumber';
|
||||||
if ($db->query($sql))
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f WHERE f.fk_soc = s.idp';
|
||||||
|
$sql .= ' AND f.rowid = '.$facid;
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num = $db->num_rows($resql);
|
||||||
|
if ($num)
|
||||||
|
{
|
||||||
|
$obj = $db->fetch_object($resql);
|
||||||
|
$total = $obj->total;
|
||||||
|
|
||||||
|
print_titre($langs->trans('DoPayment'));
|
||||||
|
print '<form action="paiement.php" method="post">';
|
||||||
|
print '<input type="hidden" name="action" value="add_paiement">';
|
||||||
|
print '<input type="hidden" name="facid" value="'.$facid.'">';
|
||||||
|
print '<input type="hidden" name="facnumber" value="'.$obj->facnumber.'">';
|
||||||
|
print '<input type="hidden" name="socid" value="'.$obj->idp.'">';
|
||||||
|
print '<input type="hidden" name="societe" value="'.$obj->nom.'">';
|
||||||
|
|
||||||
|
print '<table class="border" width="100%">';
|
||||||
|
|
||||||
|
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans('Payment').'</td>';
|
||||||
|
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">'.$obj->nom.'</td></tr>';
|
||||||
|
print '<tr><td>'.$langs->trans('Date').'</td><td>';
|
||||||
|
if (!empty($_POST['remonth']) && !empty($_POST['reday']) && !empty($_POST['reyear']))
|
||||||
|
$sel_date=mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
|
||||||
|
else
|
||||||
|
$sel_date='';
|
||||||
|
$html->select_date($sel_date);
|
||||||
|
print '</td>';
|
||||||
|
print '<td>'.$langs->trans('Comments').'</td></tr>';
|
||||||
|
print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>';
|
||||||
|
$html->select_types_paiements(empty($_POST['paiementid'])?'':$_POST['paiementid'],'paiementid');
|
||||||
|
print '</td>';
|
||||||
|
print '<td rowspan="3" valign="top">';
|
||||||
|
print '<textarea name="comment" wrap="soft" cols="40" rows="4">'.(empty($_POST['comment'])?'':$_POST['comment']).'</textarea></td></tr>';
|
||||||
|
print '<tr><td>'.$langs->trans('Numero').'</td><td><input name="num_paiement" type="text" value="'.(empty($_POST['num_paiement'])?'':$_POST['num_paiement']).'"><br><em>Numéro du chèque / virement</em></td></tr>';
|
||||||
|
if ($conf->banque->enabled)
|
||||||
|
{
|
||||||
|
print '<tr><td>'.$langs->trans('Account').'</td><td>';
|
||||||
|
$html->select_comptes(empty($_POST['accountid'])?(defined('FACTURE_RIB_NUMBER')?FACTURE_RIB_NUMBER:''):$_POST['accountid'],'accountid',0,'',1);
|
||||||
|
print '</td></tr>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print '<tr><td colspan="2"> </td></tr>';
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Autres factures impayées
|
||||||
|
*/
|
||||||
|
$sql = 'SELECT f.rowid as facid,f.facnumber,f.total_ttc,'.$db->pdate('f.datef').' as df';
|
||||||
|
$sql .= ', sum(pf.amount) as am';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
|
||||||
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
|
||||||
|
$sql .= ' WHERE f.fk_soc = '.$facture->socidp;
|
||||||
|
$sql .= ' AND f.paye = 0';
|
||||||
|
$sql .= ' AND f.fk_statut = 1'; // Statut=0 => non validée, Statut=2 => annulée
|
||||||
|
$sql .= ' GROUP BY f.facnumber';
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num = $db->num_rows($resql);
|
||||||
|
if ($num > 0)
|
||||||
{
|
{
|
||||||
$num = $db->num_rows();
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
print '<tr><td colspan="3">';
|
||||||
|
print '<table class="noborder" width="100%">';
|
||||||
|
print '<tr class="liste_titre">';
|
||||||
|
print '<td>'.$langs->trans('Bill').'</td><td align="center">'.$langs->trans('Date').'</td>';
|
||||||
|
print '<td align="right">'.$langs->trans('AmountTTC').'</td>';
|
||||||
|
print '<td align="right">'.$langs->trans('Paied').'</td>';
|
||||||
|
print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
|
||||||
|
print '<td align="center">'.$langs->trans('Amount').'</td>';
|
||||||
|
print '</tr>';
|
||||||
|
|
||||||
|
$var=True;
|
||||||
|
$total=0;
|
||||||
|
$totalrecu=0;
|
||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$objopt = $db->fetch_object();
|
$objp = $db->fetch_object($resql);
|
||||||
print "<option value=\"$objopt->id\">$objopt->libelle</option>\n";
|
$var=!$var;
|
||||||
$i++;
|
print '<tr '.$bc[$var].'>';
|
||||||
}
|
print '<td><a href="fiche.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->facnumber;
|
||||||
}
|
print '</a></td>';
|
||||||
print "</select><br>";
|
if ($objp->df > 0 )
|
||||||
print "</td>\n";
|
|
||||||
|
|
||||||
print "<td rowspan=\"4\">";
|
|
||||||
print '<textarea name="comment" wrap="soft" cols="40" rows="4"></textarea></td></tr>';
|
|
||||||
|
|
||||||
print "<tr><td>".$langs->trans("Number").":</td><td><input name=\"num_paiement\" type=\"text\"><br><em>N° du chèque ou du virement</em></td></tr>\n";
|
|
||||||
|
|
||||||
print "<tr><td>".$langs->trans("Account").":</td><td><select name=\"accountid\"><option value=\"\">-</option>\n";
|
|
||||||
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_account ORDER BY rowid";
|
|
||||||
$result = $db->query($sql);
|
|
||||||
if ($result)
|
|
||||||
{
|
{
|
||||||
$num = $db->num_rows();
|
print '<td align="center">';
|
||||||
$i = 0;
|
print dolibarr_print_date($objp->df).'</td>';
|
||||||
while ($i < $num)
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
$objopt = $db->fetch_object();
|
print '<td align="center"><b>!!!</b></td>';
|
||||||
print '<option value="'.$objopt->rowid.'"';
|
|
||||||
if (defined("FACTURE_RIB_NUMBER") && FACTURE_RIB_NUMBER == $objopt->rowid)
|
|
||||||
{
|
|
||||||
print ' selected="true"';
|
|
||||||
}
|
}
|
||||||
print '>'.$objopt->label.'</option>';
|
print '<td align="right">'.price($objp->total_ttc).'</td>';
|
||||||
$i++;
|
print '<td align="right">'.price($objp->am).'</td>';
|
||||||
}
|
print '<td align="right">'.price($objp->total_ttc - $objp->am).'</td>';
|
||||||
}
|
print '<td align="center">';
|
||||||
print "</select>";
|
$namef = 'amount_'.$objp->facid;
|
||||||
|
print '<input type="text" size="8" name="'.$namef.'">';
|
||||||
print "</td></tr>\n";
|
print "</td></tr>\n";
|
||||||
|
$total+=$objp->total;
|
||||||
|
$total_ttc+=$objp->total_ttc;
|
||||||
|
$totalrecu+=$objp->am;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
if ($i > 1)
|
||||||
|
{
|
||||||
|
// Print total
|
||||||
|
print '<tr class="liste_total">';
|
||||||
|
print '<td colspan="2" align="left">'.$langs->trans('TotalTTC').':</td>';
|
||||||
|
print '<td align="right"><b>'.price($total_ttc).'</b></td>';
|
||||||
|
print '<td align="right"><b>'.price($totalrecu).'</b></td>';
|
||||||
|
print '<td align="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
|
||||||
|
print '<td align="center"> </td>';
|
||||||
|
print "</tr>\n";
|
||||||
|
}
|
||||||
|
print "</table></td></tr>\n";
|
||||||
|
}
|
||||||
|
$db->free($resql);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
print "<tr><td valign=\"top\">".$langs->trans("RemainderToPay")." :</td><td><b>".price($total - $sumpayed).'</b> '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
/*
|
||||||
print '<tr><td>'.$langs->trans("AmountTTC").' :</td>';
|
*
|
||||||
print '<td><input name="amount" type="text" value="'.price($total - $sumpayed).'"></td></tr>';
|
*/
|
||||||
print '<tr><td colspan="3" align="center"><input type="submit" value="'.$langs->trans("Save").'"></td></tr>';
|
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans('Save').'"></td></tr>';
|
||||||
print "</form>\n";
|
print '</table>';
|
||||||
print "</table>\n";
|
print '</form>';
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,63 +340,93 @@ if ($action == 'create')
|
|||||||
/*
|
/*
|
||||||
* Affichage liste
|
* Affichage liste
|
||||||
*/
|
*/
|
||||||
if ($action == '') {
|
if (! $_GET['action'] && ! $_POST['action'])
|
||||||
|
|
||||||
if ($page == -1)
|
|
||||||
{
|
{
|
||||||
$page = 0 ;
|
if ($page == -1) $page = 0 ;
|
||||||
}
|
|
||||||
$limit = $conf->liste_limit;
|
$limit = $conf->liste_limit;
|
||||||
$offset = $limit * $page ;
|
$offset = $limit * $page ;
|
||||||
|
|
||||||
$sql = "SELECT p.rowid, ".$db->pdate("p.datep")." as dp, p.amount, f.amount as fa_amount, f.facnumber, s.nom";
|
if (! $sortorder) $sortorder='DESC';
|
||||||
$sql .=", f.rowid as facid, c.libelle as paiement_type, p.num_paiement";
|
if (! $sortfield) $sortfield='p.datep';
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p, ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."societe as s";
|
|
||||||
$sql .= " WHERE p.fk_facture_fourn = f.rowid AND p.fk_paiement = c.id AND s.idp = f.fk_soc";
|
|
||||||
|
|
||||||
|
$sql = 'SELECT p.rowid, '.$db->pdate('p.datep').' as dp, p.amount';
|
||||||
|
$sql .= ', f.amount as fa_amount, f.facnumber, s.nom';
|
||||||
|
$sql .= ', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
|
||||||
|
$sql .= ', ba.rowid as bid, ba.label';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p';
|
||||||
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn';
|
||||||
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn ';
|
||||||
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id';
|
||||||
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.idp = f.fk_soc';
|
||||||
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
|
||||||
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
|
||||||
if ($socidp)
|
if ($socidp)
|
||||||
{
|
{
|
||||||
$sql .= " AND f.fk_soc = $socidp";
|
$sql .= ' WHERE f.fk_soc = '.$socidp;
|
||||||
}
|
}
|
||||||
|
$sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
|
||||||
$sql .= " ORDER BY datep DESC";
|
|
||||||
$sql .= $db->plimit($limit + 1 ,$offset);
|
$sql .= $db->plimit($limit + 1 ,$offset);
|
||||||
$result = $db->query($sql);
|
/*
|
||||||
|
$sql = "SELECT p.rowid,".$db->pdate("p.datep")." as dp, p.amount,";
|
||||||
if ($result)
|
$sql.= " p.statut, p.num_paiement,";
|
||||||
|
$sql.= " c.libelle as paiement_type,";
|
||||||
|
$sql.= " ba.rowid as bid, ba.label";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."paiement as p,";
|
||||||
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
|
||||||
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
|
||||||
|
if ($socidp)
|
||||||
{
|
{
|
||||||
$num = $db->num_rows();
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
|
||||||
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid";
|
||||||
|
}
|
||||||
|
$sql.= " WHERE p.fk_paiement = c.id";
|
||||||
|
if ($socidp)
|
||||||
|
{
|
||||||
|
$sql.= " AND f.fk_soc = ".$socidp;
|
||||||
|
}
|
||||||
|
if ($_GET["search_montant"])
|
||||||
|
{
|
||||||
|
$sql .=" AND p.amount=".ereg_replace(",",".",$_GET["search_montant"]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num = $db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$var=True;
|
$var=True;
|
||||||
|
|
||||||
print_barre_liste($langs->trans("Payments"), $page, "paiement.php","&socidp=$socidp",$sortfield,$sortorder,'',$num);
|
print_barre_liste($langs->trans('Payments'), $page, 'paiement.php','',$sortfield,$sortorder,'',$num);
|
||||||
|
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print '<td>'.$langs->trans("Ref").'</td>';
|
print '<td>'.$langs->trans('Ref').'</td>';
|
||||||
print '<td>'.$langs->trans("Bill").'</td>';
|
print_liste_field_titre($langs->trans('Bill'),'paiement.php','facnumber','','','',$sortfield);
|
||||||
print '<td>'.$langs->trans("Company").'</td>';
|
print_liste_field_titre($langs->trans('Company'),'paiement.php','s.nom','','','',$sortfield);
|
||||||
print '<td>'.$langs->trans("Date").'</td>';
|
print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','','','',$sortfield);
|
||||||
print '<td>'.$langs->trans("Type").'</td>';
|
print_liste_field_titre($langs->trans('Type'),'paiement.php','libelle','','','',$sortfield);
|
||||||
print '<td align="right">'.$langs->trans("AmountTTC").'</td>';
|
print_liste_field_titre($langs->trans('Account'),'paiement.php','ba.label','','','',$sortfield);
|
||||||
print "<td> </td></tr>";
|
print_liste_field_titre($langs->trans('AmountTTC'),'paiement.php','fa_amount','','','align="right"',$sortfield);
|
||||||
|
print '<td> </td>';
|
||||||
|
print "</tr>\n";
|
||||||
|
|
||||||
while ($i < min($num,$limit))
|
while ($i < min($num,$limit))
|
||||||
{
|
{
|
||||||
$objp = $db->fetch_object($result);
|
$objp = $db->fetch_object($resql);
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
print "<tr $bc[$var]>";
|
print '<tr '.$bc[$var].'>';
|
||||||
print "<td><a href=\"".DOL_URL_ROOT."/fourn/paiement/fiche.php?id=$objp->rowid\">".img_object($langs->trans("ShowPayment"),"payment").'</a>';
|
print '<td><a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans('ShowPayment'),'payment').'</a>';
|
||||||
|
print ' <a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$objp->rowid.'">'.$objp->rowid.'</a></td>';
|
||||||
print " <a href=\"".DOL_URL_ROOT."/fourn/paiement/fiche.php?id=$objp->rowid\">".$objp->rowid.'</a></td>';
|
print '<td><a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->facnumber.'</a></td>';
|
||||||
|
|
||||||
|
|
||||||
print "<td><a href=\"".DOL_URL_ROOT."/fourn/facture/fiche.php?facid=$objp->facid\">".img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber.'</a></td>';
|
|
||||||
print '<td>'.$objp->nom.'</td>';
|
print '<td>'.$objp->nom.'</td>';
|
||||||
print "<td>".dolibarr_print_date($objp->dp)."</td>\n";
|
print '<td>'.dolibarr_print_date($objp->dp)."</td>\n";
|
||||||
print "<td>$objp->paiement_type $objp->num_paiement</td>\n";
|
print '<td>'.$objp->paiement_type.' '.$objp->num_paiement."</td>\n";
|
||||||
|
print '<td>';
|
||||||
|
if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"),'account').' '.$objp->label.'</a>';
|
||||||
|
else print ' ';
|
||||||
|
print '</td>';
|
||||||
print '<td align="right">'.price($objp->amount).'</td><td> </td>';
|
print '<td align="right">'.price($objp->amount).'</td><td> </td>';
|
||||||
print "</tr>";
|
print '</tr>';
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
print "</table>";
|
print "</table>";
|
||||||
@ -266,7 +435,6 @@ if ($action == '') {
|
|||||||
{
|
{
|
||||||
dolibarr_print_error($db);
|
dolibarr_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,7 +19,6 @@
|
|||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
* $Source$
|
* $Source$
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -28,167 +28,160 @@
|
|||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php");
|
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
\class PaiementFourn
|
||||||
|
\brief Classe permettant la gestion des paiements des factures fournisseurs
|
||||||
|
*/
|
||||||
|
|
||||||
class PaiementFourn
|
class PaiementFourn
|
||||||
{
|
{
|
||||||
var $id;
|
var $id;
|
||||||
var $db;
|
var $ref;
|
||||||
var $facid;
|
var $facid;
|
||||||
var $facnumber;
|
|
||||||
var $datepaye;
|
var $datepaye;
|
||||||
var $amount;
|
var $amount;
|
||||||
var $accountid;
|
var $total;
|
||||||
var $paiementid; // Cette variable contient le type de paiement, 7 pour CHQ, etc... (nom pas tres bien choisi)
|
var $author;
|
||||||
var $num_paiement;
|
var $paiementid; // Type de paiement. Stocké dans fk_paiement
|
||||||
|
// de llx_paiement qui est lié aux types de
|
||||||
|
//paiement de llx_c_paiement
|
||||||
|
var $num_paiement; // Numéro du CHQ, VIR, etc...
|
||||||
|
var $bank_account; // Id compte bancaire du paiement
|
||||||
|
var $bank_line; // Id de la ligne d'écriture bancaire
|
||||||
var $note;
|
var $note;
|
||||||
var $societe;
|
// fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
|
||||||
/*
|
// fk_paiement dans llx_paiement_facture est le rowid du paiement
|
||||||
*
|
|
||||||
*
|
var $db;
|
||||||
*
|
|
||||||
|
/**
|
||||||
|
* \brief Constructeur de la classe
|
||||||
|
* \param DB handler accès base de données
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function PaiementFourn($DB)
|
function PaiementFourn($DB)
|
||||||
{
|
{
|
||||||
$this->db = $DB ;
|
$this->db = $DB ;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
*
|
/**
|
||||||
*
|
* \brief Récupère l'objet paiement
|
||||||
|
* \param id id du paiement a récupérer
|
||||||
|
* \return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function fetch($id,$user)
|
function fetch($id)
|
||||||
{
|
{
|
||||||
/*
|
$sql = 'SELECT p.rowid,'.$this->db->pdate('p.datep').' as dp, p.amount, p.statut, p.fk_bank';
|
||||||
*/
|
$sql .=', c.libelle as paiement_type';
|
||||||
$error = 0;
|
$sql .= ', p.num_paiement, p.note, b.fk_account';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p, '.MAIN_DB_PREFIX.'c_paiement as c ';
|
||||||
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid ';
|
||||||
$sql = "SELECT fk_facture_fourn, datec, datep, amount, fk_user_author, fk_paiement, num_paiement, note";
|
$sql .= ' WHERE p.fk_paiement = c.id';
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn";
|
$sql .= ' AND p.rowid = '.$id;
|
||||||
$sql .= " WHERE rowid = ".$id.";";
|
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$num = $this->db->num_rows($resl);
|
$num = $this->db->num_rows($resql);
|
||||||
if ($num > 0)
|
if ($num > 0)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
$this->id = $obj->rowid;
|
||||||
$this->facture_id = $obj->fk_facture_fourn;
|
$this->ref = $obj->rowid;
|
||||||
$this->date = $obj->datep;
|
$this->date = $obj->dp;
|
||||||
|
$this->numero = $obj->num_paiement;
|
||||||
|
$this->bank_account = $obj->fk_account;
|
||||||
|
$this->bank_line = $obj->fk_bank;
|
||||||
$this->montant = $obj->amount;
|
$this->montant = $obj->amount;
|
||||||
|
$this->note = $obj->note;
|
||||||
|
$this->type_libelle = $obj->paiement_type;
|
||||||
}
|
$this->statut = $obj->statut;
|
||||||
else
|
|
||||||
{
|
|
||||||
$error = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "$sql";
|
|
||||||
$error = 1;
|
$error = 1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return $error;
|
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* \brief Information sur l'objet
|
|
||||||
* \param id id du paiement dont il faut afficher les infos
|
|
||||||
*/
|
|
||||||
|
|
||||||
function info($id)
|
|
||||||
{
|
{
|
||||||
$sql = "SELECT c.rowid, ".$this->db->pdate("datec")." as datec, fk_user_author";
|
$error = -2;
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as c";
|
|
||||||
$sql .= " WHERE c.rowid = $id";
|
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
|
||||||
{
|
|
||||||
if ($this->db->num_rows())
|
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object();
|
|
||||||
|
|
||||||
$this->id = $obj->idp;
|
|
||||||
|
|
||||||
if ($obj->fk_user_creat) {
|
|
||||||
$cuser = new User($this->db, $obj->fk_user_creat);
|
|
||||||
$cuser->fetch();
|
|
||||||
$this->user_creation = $cuser;
|
|
||||||
}
|
}
|
||||||
|
$this->db->free($resql);
|
||||||
if ($obj->fk_user_modif) {
|
|
||||||
$muser = new User($this->db, $obj->fk_user_modif);
|
|
||||||
$muser->fetch();
|
|
||||||
$this->user_modification = $muser;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->date_creation = $obj->datec;
|
|
||||||
$this->date_modification = $obj->tms;
|
|
||||||
|
|
||||||
}
|
|
||||||
$this->db->free();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
|
$error = -1;
|
||||||
}
|
}
|
||||||
|
return $error;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
*
|
/**
|
||||||
|
* \brief Création du paiement en base
|
||||||
|
* \param user object utilisateur qui crée
|
||||||
|
* \return int id du paiement crée, < 0 si erreur
|
||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user)
|
||||||
{
|
{
|
||||||
/*
|
$sql_err = 0;
|
||||||
* Insertion dans la base
|
|
||||||
*/
|
|
||||||
|
|
||||||
$this->amount = ereg_replace(",",".",$this->amount);
|
$this->db->begin();
|
||||||
$this->amount = ereg_replace(" ","",$this->amount);
|
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementfourn (fk_facture_fourn, datec, datep, amount, fk_user_author, fk_paiement, num_paiement, note)";
|
$this->total = 0.0;
|
||||||
$sql .= " VALUES ('$this->facid', now(), '$this->datepaye', '$this->amount', '$user->id', '$this->paiementid', '$this->num_paiement', '$this->note')";
|
foreach ($this->amounts as $key => $value)
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
|
||||||
|
|
||||||
if ($result)
|
|
||||||
{
|
{
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementfourn");
|
$val = price2num($value);
|
||||||
|
if (is_numeric($val))
|
||||||
$label = "Règlement facture $this->facnumber - $this->societe";
|
|
||||||
|
|
||||||
$account = new Account($this->db, $this->accountid);
|
|
||||||
|
|
||||||
$result = $account->addline($this->datepaye,
|
|
||||||
$this->paiementid,
|
|
||||||
$label,
|
|
||||||
-$this->amount,
|
|
||||||
$this->num_paiement);
|
|
||||||
|
|
||||||
|
|
||||||
// Mise a jour fk_bank dans llx_paiement_fourn
|
|
||||||
if ($result)
|
|
||||||
{
|
{
|
||||||
$this->bankid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank");
|
$val = price2num(round($val, 2));
|
||||||
|
$this->total += $val;
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."paiementfourn SET fk_bank=$this->bankid WHERE rowid=$this->id";
|
}
|
||||||
$result = $this->db->query($sql);
|
$this->amounts[$key] = $val;
|
||||||
|
}
|
||||||
|
$this->total = price2num($this->total);
|
||||||
|
if ($this->total <> 0) /* On accepte les montants négatifs pour les avoirs ??? */
|
||||||
|
{
|
||||||
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author)';
|
||||||
|
$sql .= ' VALUES (now(), '.$this->datepaye.', \''.$this->total.'\', '.$this->paiementid.', \''.$this->num_paiement.'\', \''.$this->note.'\', '.$user->id.')';
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn');
|
||||||
|
foreach ($this->amounts as $key => $amount)
|
||||||
|
{
|
||||||
|
$facid = $key;
|
||||||
|
if (is_numeric($amount) && $amount <> 0)
|
||||||
|
{
|
||||||
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)';
|
||||||
|
$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
|
||||||
|
if (! $this->db->query($sql) )
|
||||||
|
{
|
||||||
|
dolibarr_syslog('Paiement::Create Erreur INSERT dans paiement_facture '.$facid);
|
||||||
|
$sql_err++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "$sql";
|
dolibarr_syslog('PaiementFourn::Create Montant non numérique');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_syslog('PaiementFourn::Create Erreur INSERT dans paiementfourn');
|
||||||
|
$sql_err++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
if ( $this->total <> 0 && $sql_err == 0 ) // On accepte les montants négatifs
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
dolibarr_syslog('PaiementFourn::Create Ok Total = '.$this->total);
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
dolibarr_syslog('PaiementFourn::Create Erreur');
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -203,29 +196,215 @@ class PaiementFourn
|
|||||||
|
|
||||||
if ($filtre == 'CRDT' || $filtre == 'crédit')
|
if ($filtre == 'CRDT' || $filtre == 'crédit')
|
||||||
{
|
{
|
||||||
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE active=1 AND type IN (0,2) ORDER BY libelle";
|
$sql = 'SELECT id, libelle FROM '.MAIN_DB_PREFIX.'c_paiement WHERE active=1 AND type IN (0,2) ORDER BY libelle';
|
||||||
}
|
}
|
||||||
elseif ($filtre == 'DBIT' || $filtre == 'débit')
|
elseif ($filtre == 'DBIT' || $filtre == 'débit')
|
||||||
{
|
{
|
||||||
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE active=1 AND type IN (1,2) ORDER BY libelle";
|
$sql = 'SELECT id, libelle FROM '.MAIN_DB_PREFIX.'c_paiement WHERE active=1 AND type IN (1,2) ORDER BY libelle';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE active=1 ORDER BY libelle";
|
$sql = 'SELECT id, libelle FROM '.MAIN_DB_PREFIX.'c_paiement WHERE active=1 ORDER BY libelle';
|
||||||
}
|
}
|
||||||
$form->select($name, $sql, $id);
|
$form->select($name, $sql, $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
*
|
* \brief Supprime un paiement ainsi que les lignes qu'il a généré dans comptes
|
||||||
*
|
* Si le paiement porte sur un écriture compte qui est rapprochée, on refuse
|
||||||
*
|
* Si le paiement porte sur au moins une facture à "payée", on refuse
|
||||||
|
* \return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function delete($id)
|
function delete()
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementfourn WHERE rowid = $id";
|
$bank_line_id = $this->bank_line;
|
||||||
|
|
||||||
return $this->db->query($sql);
|
$this->db->begin();
|
||||||
|
|
||||||
|
// Vérifier si paiement porte pas sur une facture à l'état payée
|
||||||
|
// Si c'est le cas, on refuse la suppression
|
||||||
|
$billsarray=$this->getBillsArray('paye=1');
|
||||||
|
if (is_array($billsarray))
|
||||||
|
{
|
||||||
|
if (sizeof($billsarray))
|
||||||
|
{
|
||||||
|
$this->error='Impossible de supprimer un paiement portant sur au moins une facture à l\'état payé';
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier si paiement ne porte pas sur ecriture bancaire rapprochée
|
||||||
|
// Si c'est le cas, on refuse le paiement
|
||||||
|
if ($bank_line_id)
|
||||||
|
{
|
||||||
|
$accline = new AccountLine($this->db,$bank_line_id);
|
||||||
|
$accline->fetch($bank_line_id);
|
||||||
|
if ($accline->rappro)
|
||||||
|
{
|
||||||
|
$this->error='Impossible de supprimer un paiement qui a généré une écriture qui a été rapprochée';
|
||||||
|
$this->db->rollback();
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Efface la ligne de paiement (dans paiement_facture et paiement)
|
||||||
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
|
||||||
|
$sql.= ' WHERE fk_paiementfourn = '.$this->id;
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn';
|
||||||
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
if (! $result)
|
||||||
|
{
|
||||||
|
$this->error=$this->db->error();
|
||||||
|
$this->db->rollback();
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supprimer l'écriture bancaire si paiement lié à écriture
|
||||||
|
if ($bank_line_id)
|
||||||
|
{
|
||||||
|
$acc = new Account($this->db);
|
||||||
|
$result=$acc->deleteline($bank_line_id);
|
||||||
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
$this->error=$acc->error;
|
||||||
|
$this->db->rollback();
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->error;
|
||||||
|
$this->db->rollback();
|
||||||
|
return -5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Mise a jour du lien entre le paiement et la ligne générée dans llx_bank
|
||||||
|
* \param id_bank Id compte bancaire
|
||||||
|
*/
|
||||||
|
function update_fk_bank($id_bank)
|
||||||
|
{
|
||||||
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'paiementfourn set fk_bank = '.$id_bank;
|
||||||
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_print_error($this->db);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Valide le paiement
|
||||||
|
* \return int <0 si ko, >0 si ok
|
||||||
|
*/
|
||||||
|
function valide()
|
||||||
|
{
|
||||||
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'paiementfourn SET statut = 1 WHERE rowid = '.$this->id;
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_syslog('Paiement::Valide Error -1');
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Information sur l'objet
|
||||||
|
* \param id id du paiement dont il faut afficher les infos
|
||||||
|
*/
|
||||||
|
function info($id)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT c.rowid, '.$this->db->pdate('datec').' as datec, fk_user_author';
|
||||||
|
$sql .= ', '.$this->db->pdate('tms').' as tms';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as c';
|
||||||
|
$sql .= ' WHERE c.rowid = '.$id;
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num = $this->db->num_rows($resql);
|
||||||
|
if ($num)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
$this->id = $obj->idp;
|
||||||
|
if ($obj->fk_user_creat)
|
||||||
|
{
|
||||||
|
$cuser = new User($this->db, $obj->fk_user_creat);
|
||||||
|
$cuser->fetch();
|
||||||
|
$this->user_creation = $cuser;
|
||||||
|
}
|
||||||
|
if ($obj->fk_user_modif)
|
||||||
|
{
|
||||||
|
$muser = new User($this->db, $obj->fk_user_modif);
|
||||||
|
$muser->fetch();
|
||||||
|
$this->user_modification = $muser;
|
||||||
|
}
|
||||||
|
$this->date_creation = $obj->datec;
|
||||||
|
$this->date_modification = $obj->tms;
|
||||||
|
}
|
||||||
|
$this->db->free($resql);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_print_error($this->db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne la liste des factures sur lesquels porte le paiement
|
||||||
|
* \param filter Critere de filtre
|
||||||
|
* \return array Tableau des id de factures
|
||||||
|
*/
|
||||||
|
function getBillsArray($filter='')
|
||||||
|
{
|
||||||
|
$sql = 'SELECT fk_facturefourn';
|
||||||
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f';
|
||||||
|
$sql.= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.$this->id;
|
||||||
|
if ($filter) $sql.= ' AND '.$filter;
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$i=0;
|
||||||
|
$num=$this->db->num_rows($resql);
|
||||||
|
$billsarray=array();
|
||||||
|
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
$billsarray[$i]=$obj->fk_facture;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $billsarray;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->error();
|
||||||
|
dolibarr_syslog('PaiementFourn::getBillsArray Error '.$this->error.' - sql='.$sql);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,15 +28,15 @@
|
|||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require('./pre.inc.php');
|
||||||
|
|
||||||
$langs->load("suppliers");
|
$langs->load('suppliers');
|
||||||
$langs->load("products");
|
$langs->load('products');
|
||||||
$langs->load("bills");
|
$langs->load('bills');
|
||||||
$langs->load("orders");
|
$langs->load('orders');
|
||||||
$langs->load("companies");
|
$langs->load('companies');
|
||||||
|
|
||||||
$socid = $_GET["socid"];
|
$socid = $_GET['socid'];
|
||||||
/*
|
/*
|
||||||
* Sécurité accés client
|
* Sécurité accés client
|
||||||
*/
|
*/
|
||||||
@ -57,7 +57,7 @@ if ( $societe->fetch($socid) )
|
|||||||
$addons[0][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$socid;
|
$addons[0][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$socid;
|
||||||
$addons[0][1] = $societe->nom;
|
$addons[0][1] = $societe->nom;
|
||||||
|
|
||||||
llxHeader('',$langs->trans("SupplierCard").' : '.$societe->nom, $addons);
|
llxHeader('',$langs->trans('SupplierCard').' : '.$societe->nom, $addons);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Affichage onglets
|
* Affichage onglets
|
||||||
@ -65,49 +65,49 @@ if ( $societe->fetch($socid) )
|
|||||||
$h = 0;
|
$h = 0;
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/soc.php?socid='.$socid;
|
$head[$h][0] = DOL_URL_ROOT.'/soc.php?socid='.$socid;
|
||||||
$head[$h][1] = $langs->trans("Company");
|
$head[$h][1] = $langs->trans('Company');
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
if ($societe->client==1)
|
if ($societe->client==1)
|
||||||
{
|
{
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/comm/fiche.php?socid='.$socid;
|
$head[$h][0] = DOL_URL_ROOT.'/comm/fiche.php?socid='.$socid;
|
||||||
$head[$h][1] = $langs->trans("Customer");
|
$head[$h][1] = $langs->trans('Customer');
|
||||||
$h++;
|
$h++;
|
||||||
}
|
}
|
||||||
if ($societe->client==2)
|
if ($societe->client==2)
|
||||||
{
|
{
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$socid;
|
$head[$h][0] = DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$socid;
|
||||||
$head[$h][1] = $langs->trans("Prospect");
|
$head[$h][1] = $langs->trans('Prospect');
|
||||||
$h++;
|
$h++;
|
||||||
}
|
}
|
||||||
if ($societe->fournisseur)
|
if ($societe->fournisseur)
|
||||||
{
|
{
|
||||||
$hselected=$h;
|
$hselected=$h;
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$socid;
|
$head[$h][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$socid;
|
||||||
$head[$h][1] = $langs->trans("Supplier");
|
$head[$h][1] = $langs->trans('Supplier');
|
||||||
$h++;
|
$h++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($conf->compta->enabled) {
|
if ($conf->compta->enabled) {
|
||||||
$langs->load("compta");
|
$langs->load('compta');
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/compta/fiche.php?socid='.$socid;
|
$head[$h][0] = DOL_URL_ROOT.'/compta/fiche.php?socid='.$socid;
|
||||||
$head[$h][1] = $langs->trans("Accountancy");
|
$head[$h][1] = $langs->trans('Accountancy');
|
||||||
$h++;
|
$h++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/socnote.php?socid='.$societe->id;
|
$head[$h][0] = DOL_URL_ROOT.'/socnote.php?socid='.$societe->id;
|
||||||
$head[$h][1] = $langs->trans("Note");
|
$head[$h][1] = $langs->trans('Note');
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
if ($user->societe_id == 0)
|
if ($user->societe_id == 0)
|
||||||
{
|
{
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/docsoc.php?socid='.$societe->id;
|
$head[$h][0] = DOL_URL_ROOT.'/docsoc.php?socid='.$societe->id;
|
||||||
$head[$h][1] = $langs->trans("Documents");
|
$head[$h][1] = $langs->trans('Documents');
|
||||||
$h++;
|
$h++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/societe/notify/fiche.php?socid='.$societe->id;
|
$head[$h][0] = DOL_URL_ROOT.'/societe/notify/fiche.php?socid='.$societe->id;
|
||||||
$head[$h][1] = $langs->trans("Notifications");
|
$head[$h][1] = $langs->trans('Notifications');
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
dolibarr_fiche_head($head, $hselected, $societe->nom);
|
dolibarr_fiche_head($head, $hselected, $societe->nom);
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/fourn/fournisseur.class.php
|
\file htdocs/fourn/fournisseur.class.php
|
||||||
\ingroup societe
|
\ingroup fournisseur,societe
|
||||||
\brief Fichier de la classe des fournisseurs
|
\brief Fichier de la classe des fournisseurs
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
|
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
|
||||||
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -23,7 +24,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/fourn/fournisseur.facture.class.php
|
\file htdocs/fourn/fournisseur.facture.class.php
|
||||||
\ingroup fournisseur
|
\ingroup fournisseur,facture
|
||||||
\brief Fichier de la classe des factures fournisseurs
|
\brief Fichier de la classe des factures fournisseurs
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
@ -38,8 +39,7 @@ class FactureFournisseur
|
|||||||
{
|
{
|
||||||
var $id;
|
var $id;
|
||||||
var $db;
|
var $db;
|
||||||
var $socid;
|
var $socidp;
|
||||||
var $number;
|
|
||||||
var $statut;
|
var $statut;
|
||||||
var $paye;
|
var $paye;
|
||||||
var $author;
|
var $author;
|
||||||
@ -54,26 +54,27 @@ class FactureFournisseur
|
|||||||
var $total_tva;
|
var $total_tva;
|
||||||
var $total_ttc;
|
var $total_ttc;
|
||||||
var $note;
|
var $note;
|
||||||
var $db_table;
|
|
||||||
var $propalid;
|
var $propalid;
|
||||||
var $lignes;
|
var $lignes;
|
||||||
|
var $fournisseur;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructeur de la classe
|
* \brief Constructeur de la classe
|
||||||
* \param DB handler accès base de données
|
* \param DB handler accès base de données
|
||||||
* \param soc_idp id societe ("" par defaut)
|
* \param soc_idp id societe ('' par defaut)
|
||||||
* \param facid id facture ("" par defaut)
|
* \param facid id facture ('' par defaut)
|
||||||
*/
|
*/
|
||||||
function FactureFournisseur($DB, $soc_idp="", $facid="")
|
function FactureFournisseur($DB, $soc_idp='', $facid='')
|
||||||
{
|
{
|
||||||
$this->db = $DB ;
|
$this->db = $DB ;
|
||||||
$this->socidp = $soc_idp;
|
$this->socidp = $soc_idp;
|
||||||
$this->products = array();
|
$this->products = array();
|
||||||
$this->db_table = MAIN_DB_PREFIX."facture";
|
|
||||||
$this->amount = 0;
|
$this->amount = 0;
|
||||||
$this->remise = 0;
|
$this->remise = 0;
|
||||||
$this->tva = 0;
|
$this->tva = 0;
|
||||||
$this->total = 0;
|
$this->total_ht = 0;
|
||||||
|
$this->total_tva = 0;
|
||||||
|
$this->total_ttc = 0;
|
||||||
$this->propalid = 0;
|
$this->propalid = 0;
|
||||||
$this->id = $facid;
|
$this->id = $facid;
|
||||||
|
|
||||||
@ -89,9 +90,8 @@ class FactureFournisseur
|
|||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
// Nettoyage parametres
|
$socidp = $this->socidp;
|
||||||
$socid = $this->socidp;
|
$number = $this->ref;
|
||||||
$number = strtoupper($this->number);
|
|
||||||
$amount = $this->amount;
|
$amount = $this->amount;
|
||||||
$remise = $this->remise;
|
$remise = $this->remise;
|
||||||
|
|
||||||
@ -99,26 +99,25 @@ class FactureFournisseur
|
|||||||
|
|
||||||
if (! $remise) $remise = 0 ;
|
if (! $remise) $remise = 0 ;
|
||||||
$totalht = ($amount - $remise);
|
$totalht = ($amount - $remise);
|
||||||
|
// NE ME SEMBLE PLUS JUSTIFIE ICI
|
||||||
|
// $tva = tva($totalht);
|
||||||
|
// $total = $totalht + $tva;
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, fk_user_author, date_lim_reglement) ";
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, fk_user_author, date_lim_reglement) ';
|
||||||
$sql .= " VALUES ('".addslashes($number)."','".addslashes($this->libelle)."',";
|
$sql .= " VALUES ('".addslashes($number)."','".addslashes($this->libelle)."',";
|
||||||
$sql .= $this->socid.", now(),'".$this->db->idate($this->date)."','".addslashes($this->note)."', ".$user->id.",'".$this->db->idate($this->date_echeance)."');";
|
$sql .= $this->socidp.", now(),'".$this->db->idate($this->date)."','".addslashes($this->note)."', ".$user->id.",'".$this->db->idate($this->date_echeance)."');";
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
|
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn");
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn');
|
||||||
|
|
||||||
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
|
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
|
||||||
{
|
{
|
||||||
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)';
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture_fourn)";
|
$sql .= ' VALUES ('.$this->id.');';
|
||||||
$sql .= " VALUES ($this->id);";
|
$resql_insert=$this->db->query($sql);
|
||||||
if ($this->db->query($sql))
|
if ($resql_insert)
|
||||||
{
|
{
|
||||||
$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->lignes[$i][0],
|
$this->lignes[$i][0],
|
||||||
$this->lignes[$i][1],
|
$this->lignes[$i][1],
|
||||||
@ -126,7 +125,6 @@ class FactureFournisseur
|
|||||||
$this->lignes[$i][3]);
|
$this->lignes[$i][3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mise à jour prix
|
// Mise à jour prix
|
||||||
if ($this->updateprice($this->id) > 0)
|
if ($this->updateprice($this->id) > 0)
|
||||||
{
|
{
|
||||||
@ -135,7 +133,7 @@ class FactureFournisseur
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$langs->trans("FailedToUpdatePrice");
|
$this->error=$langs->trans('FailedToUpdatePrice');
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
@ -144,7 +142,7 @@ class FactureFournisseur
|
|||||||
{
|
{
|
||||||
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
|
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
|
||||||
{
|
{
|
||||||
$this->error=$langs->trans("ErrorBillRefAlreadyExists");
|
$this->error=$langs->trans('ErrorBillRefAlreadyExists');
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -163,16 +161,17 @@ class FactureFournisseur
|
|||||||
*/
|
*/
|
||||||
function fetch($rowid)
|
function fetch($rowid)
|
||||||
{
|
{
|
||||||
$sql = "SELECT fk_soc,libelle,facnumber,amount,remise,".$this->db->pdate(datef)."as df";
|
$sql = 'SELECT libelle, facnumber, amount, remise, '.$this->db->pdate(datef).'as df';
|
||||||
$sql .= ", total_ht, total_tva, total_ttc, fk_user_author";
|
$sql .= ', total_ht, total_tva, total_ttc, fk_user_author';
|
||||||
$sql .= ", fk_statut, paye, f.note,".$this->db->pdate(date_lim_reglement)."as de";
|
$sql .= ', fk_statut, paye, f.note,'.$this->db->pdate('date_lim_reglement').'as de';
|
||||||
$sql .= ", s.nom as socnom, s.idp as socidp";
|
$sql .= ', s.nom as socnom, s.idp as socidp';
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."societe as s";
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
|
||||||
$sql .= " WHERE f.rowid=$rowid AND f.fk_soc = s.idp ;";
|
$sql .= ' WHERE f.rowid='.$rowid.' AND f.fk_soc = s.idp ;';
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
if ($this->db->query($sql) )
|
if ($resql)
|
||||||
{
|
{
|
||||||
if ($this->db->num_rows())
|
$num=$this->db->num_rows($resql);
|
||||||
|
if ($num)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object();
|
$obj = $this->db->fetch_object();
|
||||||
|
|
||||||
@ -183,7 +182,7 @@ class FactureFournisseur
|
|||||||
$this->libelle = $obj->libelle;
|
$this->libelle = $obj->libelle;
|
||||||
|
|
||||||
$this->remise = $obj->remise;
|
$this->remise = $obj->remise;
|
||||||
$this->socidp = $obj->fk_soc;
|
$this->socidp = $obj->socidp;
|
||||||
|
|
||||||
$this->total_ht = $obj->total_ht;
|
$this->total_ht = $obj->total_ht;
|
||||||
$this->total_tva = $obj->total_tva;
|
$this->total_tva = $obj->total_tva;
|
||||||
@ -194,23 +193,24 @@ class FactureFournisseur
|
|||||||
$this->statut = $obj->fk_statut;
|
$this->statut = $obj->fk_statut;
|
||||||
$this->paye = $obj->paye;
|
$this->paye = $obj->paye;
|
||||||
|
|
||||||
$this->socidp = $obj->socidp;
|
|
||||||
$this->socnom = $obj->socnom;
|
$this->socnom = $obj->socnom;
|
||||||
$this->note = $obj->note;
|
$this->note = $obj->note;
|
||||||
$this->db->free();
|
$this->db->free($resql);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lignes
|
* Lignes
|
||||||
*/
|
*/
|
||||||
$sql = "SELECT rowid,description, pu_ht, qty, tva_taux, tva, total_ht, total_ttc FROM ".MAIN_DB_PREFIX."facture_fourn_det WHERE fk_facture_fourn=".$this->id;
|
$sql = 'SELECT rowid,description, pu_ht, qty, tva_taux, tva, total_ht, total_ttc';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det';
|
||||||
if ($this->db->query($sql) )
|
$sql .= ' WHERE fk_facture_fourn='.$this->id;
|
||||||
|
$resql_rows = $this->db->query($sql);
|
||||||
|
if ($resql_rows)
|
||||||
{
|
{
|
||||||
$num = $this->db->num_rows();
|
$num_rows = $this->db->num_rows($resql_rows);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
if ($num)
|
if ($num_rows)
|
||||||
{
|
{
|
||||||
while ($i < $num)
|
while ($i < $num_rows)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object();
|
$obj = $this->db->fetch_object();
|
||||||
$this->lignes[$i][0] = stripslashes($obj->description);
|
$this->lignes[$i][0] = stripslashes($obj->description);
|
||||||
@ -224,6 +224,7 @@ class FactureFournisseur
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->db->free($resql_rows);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -237,22 +238,33 @@ class FactureFournisseur
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Recupére l'objet fournisseur lié à la facture
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function fetch_fournisseur()
|
||||||
|
{
|
||||||
|
$fournisseur = new Fournisseur($this->db);
|
||||||
|
$fournisseur->fetch($this->socidp);
|
||||||
|
$this->fournisseur = $fournisseur;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Supprime la facture
|
* \brief Supprime la facture
|
||||||
* \param rowid id de la facture à supprimer
|
* \param rowid id de la facture à supprimer
|
||||||
*/
|
*/
|
||||||
function delete($rowid)
|
function delete($rowid)
|
||||||
{
|
{
|
||||||
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn WHERE rowid = '.$rowid.' AND fk_statut = 0;';
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn WHERE rowid = $rowid AND fk_statut = 0";
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
if ( $this->db->query( $sql) )
|
|
||||||
{
|
{
|
||||||
if ( $this->db->affected_rows() )
|
$num = $this->db->affected_rows($resql);
|
||||||
|
if ($num)
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det WHERE fk_facture_fourn = $rowid;";
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det WHERE fk_facture_fourn = '.$rowid.';';
|
||||||
|
$resql2 = $this->db->query($sql);
|
||||||
if ($this->db->query( $sql) )
|
if ($resql2)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -270,16 +282,14 @@ class FactureFournisseur
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Tag la facture comme payée complètement
|
* \brief Tag la facture comme payée complètement
|
||||||
* \param user Objet utilisateur qui modifie
|
* \param userid utilisateur qui modifie l'état
|
||||||
* \return int <0 si ko, >0 si ok
|
* \return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function set_payed($user)
|
function set_payed($user)
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set paye = 1 WHERE rowid = '.$this->id.';';
|
||||||
$sql.= " SET paye = 1";
|
$resql = $this->db->query($sql);
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
if (! $resql)
|
||||||
$result = $this->db->query($sql);
|
|
||||||
if (! $result)
|
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
return -1;
|
return -1;
|
||||||
@ -289,16 +299,16 @@ class FactureFournisseur
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Tag la facture comme validée et valide la facture
|
* \brief Tag la facture comme validée et valide la facture
|
||||||
* \param user Objet utilisateur qui modifie
|
* \param userid utilisateur qui valide la facture
|
||||||
* \return int <0 si ko, >0 si ok
|
|
||||||
*/
|
*/
|
||||||
function set_valid($user)
|
function set_valid($userid)
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
|
||||||
$sql.= " SET fk_statut = 1, fk_user_valid = ".$user->id;
|
$sql.= " SET fk_statut = 1, fk_user_valid = ".$user->id;
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
$result = $this->db->query( $sql);
|
$resql = $this->db->query($sql);
|
||||||
if (! $result) {
|
if (! $resql)
|
||||||
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,23 +323,20 @@ class FactureFournisseur
|
|||||||
*/
|
*/
|
||||||
function addline($desc, $pu, $tauxtva, $qty)
|
function addline($desc, $pu, $tauxtva, $qty)
|
||||||
{
|
{
|
||||||
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)';
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture_fourn)";
|
$sql .= ' VALUES ('.$this->id.');';
|
||||||
$sql .= " VALUES ($this->id);";
|
$resql = $this->db->query($sql);
|
||||||
if ($this->db->query($sql) )
|
if ($resql)
|
||||||
{
|
{
|
||||||
$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, $desc, $pu, $tauxtva, $qty);
|
$this->updateline($idligne, $desc, $pu, $tauxtva, $qty);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mise a jour prix facture
|
// Mise a jour prix facture
|
||||||
$this->updateprice($this->id);
|
$this->updateprice($this->id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -343,8 +350,8 @@ class FactureFournisseur
|
|||||||
*/
|
*/
|
||||||
function updateline($id, $label, $puht, $tauxtva, $qty=1)
|
function updateline($id, $label, $puht, $tauxtva, $qty=1)
|
||||||
{
|
{
|
||||||
$puht = ereg_replace(",",".",$puht);
|
$puht = price2num($puht);
|
||||||
$qty = ereg_replace(",",".",$qty);
|
$qty = price2num($qty);
|
||||||
|
|
||||||
if (is_numeric($puht) && is_numeric($qty))
|
if (is_numeric($puht) && is_numeric($qty))
|
||||||
{
|
{
|
||||||
@ -352,15 +359,16 @@ class FactureFournisseur
|
|||||||
$tva = ($totalht * $tauxtva / 100);
|
$tva = ($totalht * $tauxtva / 100);
|
||||||
$totalttc = $totalht + $tva;
|
$totalttc = $totalht + $tva;
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det ";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn_det ';
|
||||||
$sql .= "SET description ='".addslashes($label)."'";
|
$sql .= 'SET ';
|
||||||
$sql .= ", pu_ht = " .ereg_replace(",",".",$puht);
|
$sql .= 'description =\''.addslashes($label).'\'';
|
||||||
$sql .= ", qty =" .ereg_replace(",",".",$qty);
|
$sql .= ', pu_ht = ' .$puht;
|
||||||
$sql .= ", total_ht=" .ereg_replace(",",".",$totalht);
|
$sql .= ', qty =' .$qty;
|
||||||
$sql .= ", tva=" .ereg_replace(",",".",$tva);
|
$sql .= ', total_ht=' .price2num($totalht);
|
||||||
$sql .= ", tva_taux=" .ereg_replace(",",".",$tauxtva);
|
$sql .= ', tva=' .price2num($tva);
|
||||||
$sql .= ", total_ttc=".ereg_replace(",",".",$totalttc);
|
$sql .= ', tva_taux=' .price2num($tauxtva);
|
||||||
$sql .= " WHERE rowid = ".$id;
|
$sql .= ', total_ttc='.price2num($totalttc);
|
||||||
|
$sql .= ' WHERE rowid = '.$id.';';
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
@ -383,17 +391,15 @@ class FactureFournisseur
|
|||||||
function deleteline($rowid)
|
function deleteline($rowid)
|
||||||
{
|
{
|
||||||
// Supprime ligne
|
// Supprime ligne
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det ";
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det ';
|
||||||
$sql .= " WHERE rowid = $rowid";
|
$sql .= ' WHERE rowid = '.$rowid.';';
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
if (! $this->db->query($sql) )
|
if (! $resql)
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mise a jour prix facture
|
// Mise a jour prix facture
|
||||||
$this->updateprice($this->id);
|
$this->updateprice($this->id);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,33 +414,32 @@ class FactureFournisseur
|
|||||||
$total_tva = 0;
|
$total_tva = 0;
|
||||||
$total_ttc = 0;
|
$total_ttc = 0;
|
||||||
|
|
||||||
$sql = "SELECT sum(total_ht), sum(tva), sum(total_ttc) FROM ".MAIN_DB_PREFIX."facture_fourn_det";
|
$sql = 'SELECT sum(total_ht), sum(tva), sum(total_ttc) FROM '.MAIN_DB_PREFIX.'facture_fourn_det';
|
||||||
$sql .= " WHERE fk_facture_fourn = $facid;";
|
$sql .= ' WHERE fk_facture_fourn = '.$facid.';';
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
$result = $this->db->query($sql);
|
if ($resql)
|
||||||
|
|
||||||
if ($result)
|
|
||||||
{
|
{
|
||||||
if ($this->db->num_rows() )
|
$num = $this->db->num_rows($resql);
|
||||||
|
if ($num)
|
||||||
{
|
{
|
||||||
$row = $this->db->fetch_row();
|
$row = $this->db->fetch_row();
|
||||||
$total_ht = $row[0];
|
$total_ht = $row[0];
|
||||||
$total_tva = $row[1];
|
$total_tva = $row[1];
|
||||||
$total_ttc = $row[2];
|
$total_ttc = $row[2];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$this->db->free($resql);
|
||||||
|
|
||||||
$total_ht = $total_ht != '' ? $total_ht : 0;
|
$total_ht = $total_ht != '' ? $total_ht : 0;
|
||||||
$total_tva = $total_tva != '' ? $total_tva : 0;
|
$total_tva = $total_tva != '' ? $total_tva : 0;
|
||||||
$total_ttc = $total_ttc != '' ? $total_ttc : 0;
|
$total_ttc = $total_ttc != '' ? $total_ttc : 0;
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn SET";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn SET';
|
||||||
$sql .= " total_ht = ". ereg_replace(",",".",$total_ht);
|
$sql .= ' total_ht = '. price2num($total_ht);
|
||||||
$sql .= ",total_tva = ".ereg_replace(",",".",$total_tva);
|
$sql .= ',total_tva = '.price2num($total_tva);
|
||||||
$sql .= ",total_ttc = ".ereg_replace(",",".",$total_ttc);
|
$sql .= ',total_ttc = '.price2num($total_ttc);
|
||||||
$sql .= " WHERE rowid = $facid ;";
|
$sql .= ' WHERE rowid = '.$facid.';';
|
||||||
|
$resql2 = $this->db->query($sql);
|
||||||
$result = $this->db->query($sql);
|
if ($resql2)
|
||||||
if ($result)
|
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -470,16 +475,16 @@ class FactureFournisseur
|
|||||||
function LibStatutShort($paye,$statut)
|
function LibStatutShort($paye,$statut)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
$langs->load("bills");
|
$langs->load('bills');
|
||||||
if (! $paye)
|
if (! $paye)
|
||||||
{
|
{
|
||||||
if ($statut == 0) return $langs->trans("BillShortStatusDraft");
|
if ($statut == 0) return $langs->trans('BillShortStatusDraft');
|
||||||
if ($statut == 3) return $langs->trans("BillShortStatusCanceled");
|
if ($statut == 3) return $langs->trans('BillShortStatusCanceled');
|
||||||
return $langs->trans("BillShortValidated");
|
return $langs->trans('BillShortValidated');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $langs->trans("BillShortStatusPayed");
|
return $langs->trans('BillShortStatusPayed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,16 +497,16 @@ class FactureFournisseur
|
|||||||
function LibStatut($paye,$statut)
|
function LibStatut($paye,$statut)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
$langs->load("bills");
|
$langs->load('bills');
|
||||||
if (! $paye)
|
if (! $paye)
|
||||||
{
|
{
|
||||||
if ($statut == 0) return $langs->trans("BillStatusDraft");
|
if ($statut == 0) return $langs->trans('BillStatusDraft');
|
||||||
if ($statut == 3) return $langs->trans("BillStatusCanceled");
|
if ($statut == 3) return $langs->trans('BillStatusCanceled');
|
||||||
return $langs->trans("BillStatusValidated");
|
return $langs->trans('BillStatusValidated');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $langs->trans("BillStatusPayed");
|
return $langs->trans('BillStatusPayed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,17 +520,17 @@ class FactureFournisseur
|
|||||||
function PayedLibStatut($paye,$statut,$amount=0)
|
function PayedLibStatut($paye,$statut,$amount=0)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
$langs->load("bills");
|
$langs->load('bills');
|
||||||
if (! $paye)
|
if (! $paye)
|
||||||
{
|
{
|
||||||
if ($statut == 0) return $langs->trans("BillShortStatusDraft");
|
if ($statut == 0) return $langs->trans('BillShortStatusDraft');
|
||||||
if ($statut == 3) return $langs->trans("BillStatusCanceled");
|
if ($statut == 3) return $langs->trans('BillStatusCanceled');
|
||||||
if ($amount) return $langs->trans("BillStatusStarted");
|
if ($amount) return $langs->trans('BillStatusStarted');
|
||||||
return $langs->trans("BillStatusNotPayed");
|
return $langs->trans('BillStatusNotPayed');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $langs->trans("BillStatusPayed");
|
return $langs->trans('BillStatusPayed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,10 +545,10 @@ class FactureFournisseur
|
|||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$this->nbtodo=$this->nbtodolate=0;
|
$this->nbtodo=$this->nbtodolate=0;
|
||||||
$sql = "SELECT ff.rowid,".$this->db->pdate("ff.date_lim_reglement")." as datefin";
|
$sql = 'SELECT ff.rowid,'.$this->db->pdate('ff.date_lim_reglement').' as datefin';
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as ff';
|
||||||
$sql.= " WHERE ff.paye=0";
|
$sql.= ' WHERE ff.paye=0;';
|
||||||
if ($user->societe_id) $sql.=" AND fk_soc = ".$user->societe_id;
|
if ($user->societe_id) $sql.=' AND fk_soc = '.$user->societe_id;
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@ -552,6 +557,7 @@ class FactureFournisseur
|
|||||||
$this->nbtodo++;
|
$this->nbtodo++;
|
||||||
if ($obj->datefin < (time() - $conf->facture->fournisseur->warning_delay)) $this->nbtodolate++;
|
if ($obj->datefin < (time() - $conf->facture->fournisseur->warning_delay)) $this->nbtodolate++;
|
||||||
}
|
}
|
||||||
|
$this->db->free($resql);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -20,121 +21,226 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file htdocs/compta/paiement/fiche.php
|
/**
|
||||||
|
\file htdocs/fourn/paiement/fiche.php
|
||||||
\ingroup facture
|
\ingroup facture
|
||||||
\brief Onglet paiement d'un paiement
|
\brief Onglet paiement d'un paiement
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require('./pre.inc.php');
|
||||||
|
|
||||||
require(DOL_DOCUMENT_ROOT."/fourn/facture/paiementfourn.class.php");
|
require(DOL_DOCUMENT_ROOT.'/fourn/facture/paiementfourn.class.php');
|
||||||
|
|
||||||
$user->getrights('facture');
|
$user->getrights('facture');
|
||||||
|
|
||||||
$langs->load("bills");
|
$langs->load('bills');
|
||||||
$langs->load("banks");
|
$langs->load('banks');
|
||||||
$langs->load("companies");
|
$langs->load('companies');
|
||||||
|
|
||||||
|
$mesg='';
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Actions
|
||||||
|
*/
|
||||||
|
if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->facture->creer)
|
||||||
|
{
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
$paiement = new PaiementFourn($db);
|
||||||
|
$paiement->fetch($_GET['id']);
|
||||||
|
$result = $paiement->delete();
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$db->commit();
|
||||||
|
Header('Location: /fourn/facture/paiement.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg='<div class="error">'.$paiement->error.'</div>';
|
||||||
|
$db->rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_POST['action'] == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user->rights->facture->creer)
|
||||||
|
{
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
$paiement = new PaiementFourn($db);
|
||||||
|
$paiement->id = $_GET['id'];
|
||||||
|
if ( $paiement->valide() == 0 )
|
||||||
|
{
|
||||||
|
$db->commit();
|
||||||
|
Header('Location: fiche.php?id='.$paiement->id);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg='<div class="error">'.$paiement->error.'</div>';
|
||||||
|
$db->rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Visualisation de la fiche
|
* Visualisation de la fiche
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
llxHeader();
|
llxHeader();
|
||||||
|
|
||||||
|
$paiement = new PaiementFourn($db);
|
||||||
|
$paiement->fetch($_GET['id']);
|
||||||
|
|
||||||
|
$html = new Form($db);
|
||||||
|
|
||||||
$h=0;
|
$h=0;
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$_GET["id"];
|
$head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$_GET['id'];
|
||||||
$head[$h][1] = $langs->trans("Card");
|
$head[$h][1] = $langs->trans('Card');
|
||||||
$hselected = $h;
|
$hselected = $h;
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$_GET["id"];
|
$head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$_GET['id'];
|
||||||
$head[$h][1] = $langs->trans("Info");
|
$head[$h][1] = $langs->trans('Info');
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
dolibarr_fiche_head($head, $hselected, $langs->trans("Payment").": ".$_GET["id"]);
|
|
||||||
|
|
||||||
|
dolibarr_fiche_head($head, $hselected, $langs->trans('Payment').': '.$paiement->ref);
|
||||||
$facture = new FactureFournisseur($db);
|
|
||||||
$paiement = new PaiementFourn($db);
|
|
||||||
|
|
||||||
if ($paiement->fetch($_GET["id"], $user) == 0)
|
|
||||||
{
|
|
||||||
$html = new Form($db);
|
|
||||||
|
|
||||||
$facture->fetch($paiement->facture_id);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Confirmation de la suppression du paiement
|
* Confirmation de la suppression du paiement
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
if ($_GET["action"] == 'delete')
|
if ($_GET['action'] == 'delete')
|
||||||
{
|
{
|
||||||
$html->form_confirm("fiche.php?id=$paiement->id","Supprimer le paiement","Etes-vous sûr de vouloir supprimer ce paiement ?","confirm_delete");
|
$html->form_confirm('fiche.php?id='.$paiement->id, 'Supprimer le paiement', 'Etes-vous sûr de vouloir supprimer ce paiement ?', 'confirm_delete');
|
||||||
print '<br>';
|
print '<br>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["action"] == 'valide')
|
/*
|
||||||
|
* Confirmation de la validation du paiement
|
||||||
|
*/
|
||||||
|
if ($_GET['action'] == 'valide')
|
||||||
{
|
{
|
||||||
$html->form_confirm("fiche.php?id=$paiement->id","Valider le paiement","Etes-vous sûr de vouloir valider ce paiment, auncune modification n'est possible une fois le paiement validé ?","confirm_valide");
|
$html->form_confirm('fiche.php?id='.$paiement->id, 'Valider le paiement', 'Etes-vous sûr de vouloir valider ce paiment, auncune modification n\'est possible une fois le paiement validé ?', 'confirm_valide');
|
||||||
print '<br>';
|
print '<br>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<table class="noborder" width="100%">';
|
|
||||||
|
|
||||||
print '<tr><td valign="top">';
|
if ($mesg) print $mesg.'<br>';
|
||||||
|
|
||||||
if ($paiement->bank_account) {
|
|
||||||
|
print '<table class="border" width="100%">';
|
||||||
|
|
||||||
|
print '<tr><td valign="top" width="140">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';
|
||||||
|
if ($conf->banque->enabled)
|
||||||
|
{
|
||||||
|
if ($paiement->bank_account)
|
||||||
|
{
|
||||||
// Si compte renseigné, on affiche libelle
|
// Si compte renseigné, on affiche libelle
|
||||||
$bank=new Account($db);
|
$bank=new Account($db);
|
||||||
$bank->fetch($paiement->bank_account);
|
$bank->fetch($paiement->bank_account);
|
||||||
print $langs->trans("BankAccount").' : '.$bank->label.'<br>';
|
|
||||||
}
|
|
||||||
print $langs->trans("Date").' : '.dolibarr_print_date($paiement->date)."<br>";
|
|
||||||
print $langs->trans("Bill").' : <a href="../facture/fiche.php?facid='.$facture->id.'">'.$facture->ref."</a><br>";
|
|
||||||
print $langs->trans("Type").' : '.$paiement->type_libelle."<br>";
|
|
||||||
if ($paiement->numero) { print $langs->trans("Numero").' : '.$paiement->numero."<br>"; }
|
|
||||||
print $langs->trans("Amount").' : '.$paiement->montant." ".$conf->monnaie."<br>";
|
|
||||||
print '</td></tr>';
|
|
||||||
print "</table>";
|
|
||||||
|
|
||||||
print nl2br($paiement->note);
|
$bankline=new AccountLine($db);
|
||||||
|
$bankline->fetch($paiement->bank_line);
|
||||||
|
|
||||||
|
print '<tr>';
|
||||||
|
print '<td valign="top" width="140">'.$langs->trans('BankAccount').'</td>';
|
||||||
|
print '<td><a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$bank->id.'">'.img_object($langs->trans('ShowAccount'),'account').' '.$bank->label.'</a></td>';
|
||||||
|
print '<td>'.$langs->trans('BankLineConciliated').'</td><td>'.yn($bankline->rappro).'</td>';
|
||||||
|
print '</tr>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print '<tr><td valign="top" width="140">'.$langs->trans('Date').'</td><td colspan="3">'.dolibarr_print_date($paiement->date).'</td></tr>';
|
||||||
|
print '<tr><td valign="top">'.$langs->trans('Type').'</td><td colspan="3">'.$paiement->type_libelle.'</td></tr>';
|
||||||
|
if ($paiement->numero)
|
||||||
|
{
|
||||||
|
print '<tr><td valign="top">'.$langs->trans('Numero').'</td><td colspan="3">'.$paiement->numero.'</td></tr>';
|
||||||
|
}
|
||||||
|
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
||||||
|
print '<tr><td valign="top">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($paiement->note).'</td></tr>';
|
||||||
|
print '</table>';
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
||||||
print "<br></div>";
|
|
||||||
|
|
||||||
print '<div class="tabsAction">';
|
|
||||||
|
|
||||||
if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET["action"] == '')
|
|
||||||
{
|
|
||||||
print '<a class="tabAction" href="fiche.php?id='.$_GET["id"].'&action=valide">'.$langs->trans("Valid").'</a>';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($user->societe_id == 0 && $allow_delete && $paiement->statut == 0 && $_GET["action"] == '')
|
|
||||||
{
|
|
||||||
print '<a class="butDelete" href="fiche.php?id='.$_GET["id"].'&action=delete">'.$langs->trans("Delete").'</a>';
|
|
||||||
|
|
||||||
}
|
|
||||||
print "</div>";
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
$allow_delete = 1 ;
|
||||||
|
$sql = 'SELECT f.facnumber, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.idp';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
|
||||||
|
$sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.idp';
|
||||||
|
$sql .= ' AND pf.fk_paiementfourn = '.$paiement->id;
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num = $db->num_rows($resql);
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
$total = 0;
|
||||||
|
print '<br><table class="noborder" width="100%">';
|
||||||
|
print '<tr class="liste_titre">';
|
||||||
|
print '<td>'.$langs->trans('Bill').'</td><td>'.$langs->trans('Company').'</td>';
|
||||||
|
print '<td align="right">'.$langs->trans('AmountTTC').'</td><td align="center">'.$langs->trans('Status').'</td>';
|
||||||
|
print "</tr>\n";
|
||||||
|
|
||||||
|
if ($num > 0)
|
||||||
|
{
|
||||||
|
$var=True;
|
||||||
|
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$objp = $db->fetch_object($resql);
|
||||||
|
$var=!$var;
|
||||||
|
print '<tr '.$bc[$var].'>';
|
||||||
|
print '<td><a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' ';
|
||||||
|
print $objp->facnumber;
|
||||||
|
print "</a></td>\n";
|
||||||
|
print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
|
||||||
|
print '<td align="right">'.price($objp->amount).'</td>';
|
||||||
|
$fac=new FactureFournisseur($db);
|
||||||
|
print '<td align="center">'.$fac->LibStatut($objp->paye,$objp->fk_statut).'</td>';
|
||||||
|
print "</tr>\n";
|
||||||
|
if ($objp->paye == 1)
|
||||||
|
{
|
||||||
|
$allow_delete = 0;
|
||||||
|
}
|
||||||
|
$total = $total + $objp->amount;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$var=!$var;
|
||||||
|
|
||||||
|
print "</table>\n";
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "Erreur de lecture";
|
dolibarr_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print '</div>';
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Boutons Actions
|
||||||
|
*/
|
||||||
|
|
||||||
|
print '<div class="tabsAction">';
|
||||||
|
|
||||||
|
if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET['action'] == '')
|
||||||
|
{
|
||||||
|
print '<a class="tabAction" href="fiche.php?id='.$_GET['id'].'&action=valide">'.$langs->trans('Valid').'</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->societe_id == 0 && $allow_delete && $paiement->statut == 0 && $_GET['action'] == '')
|
||||||
|
{
|
||||||
|
print '<a class="butDelete" href="fiche.php?id='.$_GET['id'].'&action=delete">'.$langs->trans('Delete').'</a>';
|
||||||
|
}
|
||||||
|
print '</div>';
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
llxFooter("<em>Dernière modification $Date$ révision $Revision$</em>");
|
llxFooter("<em>Dernière modification $Date$ révision $Revision$</em>");
|
||||||
|
|||||||
@ -1948,3 +1948,16 @@ alter table llx_facture add model varchar(50) after note;
|
|||||||
alter table llx_facturedet modify fk_product integer NULL;
|
alter table llx_facturedet modify fk_product integer NULL;
|
||||||
alter table llx_contratdet modify fk_product integer NULL;
|
alter table llx_contratdet modify fk_product integer NULL;
|
||||||
update llx_facturedet set fk_product = null where fk_product=0;
|
update llx_facturedet set fk_product = null where fk_product=0;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `llx_paiementfourn_facturefourn`
|
||||||
|
(
|
||||||
|
`rowid` int(11) NOT NULL auto_increment,
|
||||||
|
`fk_paiementfourn` int(11) default NULL,
|
||||||
|
`fk_facturefourn` int(11) default NULL,
|
||||||
|
`amount` double default '0',
|
||||||
|
PRIMARY KEY (`rowid`),
|
||||||
|
KEY `idx_fk_facture` (`fk_facturefourn`),
|
||||||
|
KEY `idx_fk_paiement` (`fk_paiementfourn`)
|
||||||
|
) TYPE=innodb;
|
||||||
|
|
||||||
|
ALTER TABLE `llx_paiementfourn` ADD `statut` SMALLINT( 6 ) NOT NULL ;
|
||||||
|
|||||||
32
mysql/tables/llx_paiementfourn_facturefourn.sql
Normal file
32
mysql/tables/llx_paiementfourn_facturefourn.sql
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
-- ============================================================================
|
||||||
|
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
-- Copyright (C) 2005 Marc Barilley / Océbo <marc@ocebo.com>
|
||||||
|
--
|
||||||
|
-- This program is free software; you can redistribute it and/or modify
|
||||||
|
-- it under the terms of the GNU General Public License as published by
|
||||||
|
-- the Free Software Foundation; either version 2 of the License, or
|
||||||
|
-- (at your option) any later version.
|
||||||
|
--
|
||||||
|
-- This program is distributed in the hope that it will be useful,
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
-- GNU General Public License for more details.
|
||||||
|
--
|
||||||
|
-- You should have received a copy of the GNU General Public License
|
||||||
|
-- along with this program; if not, write to the Free Software
|
||||||
|
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
--
|
||||||
|
-- $Id$
|
||||||
|
-- $Source$
|
||||||
|
--
|
||||||
|
-- ===========================================================================
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `llx_paiementfourn_facturefourn` (
|
||||||
|
`rowid` int(11) NOT NULL auto_increment,
|
||||||
|
`fk_paiementfourn` int(11) default NULL,
|
||||||
|
`fk_facturefourn` int(11) default NULL,
|
||||||
|
`amount` double default '0',
|
||||||
|
PRIMARY KEY (`rowid`),
|
||||||
|
KEY `idx_fk_facture` (`fk_facturefourn`),
|
||||||
|
KEY `idx_fk_paiement` (`fk_paiementfourn`)
|
||||||
|
) TYPE=innodb;
|
||||||
Loading…
Reference in New Issue
Block a user