New: Possibilit de gnrer une facture depuis un contrat
This commit is contained in:
parent
f37af21107
commit
888e19438b
@ -124,7 +124,7 @@ if ($_POST["action"] == 'add')
|
||||
$facture->remise = $_POST["remise"];
|
||||
$facture->remise_percent = $_POST["remise_percent"];
|
||||
|
||||
if (!$_POST["propalid"] && !$_POST["commandeid"])
|
||||
if (! $_POST["propalid"] && ! $_POST["commandeid"] && ! $_POST["contratid"])
|
||||
{
|
||||
for ($i = 1 ; $i <= $NBLINES ; $i++)
|
||||
{
|
||||
@ -187,7 +187,7 @@ if ($_POST["action"] == 'add')
|
||||
}
|
||||
|
||||
/*
|
||||
* Commande
|
||||
* Si création depuis commande
|
||||
*/
|
||||
if ($_POST["commandeid"])
|
||||
{
|
||||
@ -222,6 +222,43 @@ if ($_POST["action"] == 'add')
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Si création depuis contrat
|
||||
*/
|
||||
if ($_POST["contratid"])
|
||||
{
|
||||
$facture->contratid = $_POST["contratid"];
|
||||
$facid = $facture->create($user);
|
||||
|
||||
if ($facid)
|
||||
{
|
||||
$contrat = New Contrat($db);
|
||||
if ( $contrat->fetch($_POST["contratid"]) )
|
||||
{
|
||||
$lines = $contrat->fetch_lignes();
|
||||
for ($i = 0 ; $i < sizeof($lines) ; $i++)
|
||||
{
|
||||
$result = $facture->addline($facid,
|
||||
addslashes($lines[$i]->description),
|
||||
$lines[$i]->subprice,
|
||||
$lines[$i]->qty,
|
||||
$lines[$i]->tva_tx,
|
||||
$lines[$i]->product_id,
|
||||
$lines[$i]->remise_percent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("UnknownError");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
// Fin création facture, on l'affiche
|
||||
if ($facid)
|
||||
{
|
||||
Header("Location: facture.php?facid=".$facid);
|
||||
@ -514,33 +551,39 @@ if ($_GET["action"] == 'create')
|
||||
{
|
||||
print_titre($langs->trans("NewBill"));
|
||||
|
||||
$soc = new Societe($db);
|
||||
|
||||
if ($_GET["propalid"])
|
||||
{
|
||||
$propal = New Propal($db);
|
||||
$propal->fetch($_GET["propalid"]);
|
||||
$societe_id = $propal->soc_id;
|
||||
$soc->fetch($societe_id);
|
||||
}
|
||||
elseif ($_GET["commandeid"])
|
||||
{
|
||||
$commande = New Commande($db);
|
||||
$commande->fetch($_GET["commandeid"]);
|
||||
$societe_id = $commande->soc_id;
|
||||
$soc->fetch($societe_id);
|
||||
}
|
||||
elseif ($_GET["contratid"])
|
||||
{
|
||||
$contrat = New Contrat($db);
|
||||
$contrat->fetch($_GET["contratid"]);
|
||||
$societe_id = $contrat->soc_id;
|
||||
$societe_id = $contrat->societe->id;
|
||||
$soc=$contrat->societe;
|
||||
}
|
||||
else
|
||||
{
|
||||
$societe_id=$socidp;
|
||||
$soc->fetch($societe_id);
|
||||
}
|
||||
else $societe_id=$socidp;
|
||||
|
||||
$soc = new Societe($db);
|
||||
$soc->fetch($societe_id);
|
||||
|
||||
print '<form action="facture.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n";
|
||||
print '<input type="hidden" name="remise_percent" value="0">';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
@ -576,9 +619,9 @@ if ($_GET["action"] == 'create')
|
||||
print '</textarea></td></tr>';
|
||||
|
||||
// Conditions de réglement
|
||||
$id_condition_paiements_defaut=1;
|
||||
$cond_reglement_id_defaut=1;
|
||||
print "<tr><td nowrap>".$langs->trans("PaymentConditions")."</td><td>";
|
||||
$html->select_conditions_paiements($id_condition_paiements_defaut,'cond_reglement_id');
|
||||
$html->select_conditions_paiements($cond_reglement_id_defaut,'cond_reglement_id');
|
||||
print "</td></tr>";
|
||||
|
||||
// Mode de réglement
|
||||
@ -601,8 +644,7 @@ if ($_GET["action"] == 'create')
|
||||
|
||||
if ($_GET["propalid"] > 0)
|
||||
{
|
||||
$amount = ($propal->price);
|
||||
print '<input type="hidden" name="amount" value="'.$amount.'">'."\n";
|
||||
print '<input type="hidden" name="amount" value="'.$propal->price.'">'."\n";
|
||||
print '<input type="hidden" name="total" value="'.$propal->total.'">'."\n";
|
||||
print '<input type="hidden" name="remise" value="'.$propal->remise.'">'."\n";
|
||||
print '<input type="hidden" name="remise_percent" value="'.$propal->remise_percent.'">'."\n";
|
||||
@ -611,13 +653,15 @@ if ($_GET["action"] == 'create')
|
||||
|
||||
print '<tr><td>'.$langs->trans("Proposal").'</td><td colspan="2">'.$propal->ref.'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("GlobalDiscount").'</td><td colspan="2">'.$propal->remise_percent.'%</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("TotalHT").'</td><td colspan="2">'.price($amount).'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("TotalHT").'</td><td colspan="2">'.price($propal->price).'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("VAT").'</td><td colspan="2">'.price($propal->tva)."</td></tr>";
|
||||
print '<tr><td>'.$langs->trans("TotalTTC").'</td><td colspan="2">'.price($propal->total)."</td></tr>";
|
||||
}
|
||||
elseif ($_GET["commandeid"] > 0)
|
||||
{
|
||||
$commande->remise_percent=$soc->remise_client;
|
||||
print '<input type="hidden" name="commandeid" value="'.$commande->id.'">';
|
||||
print '<input type="hidden" name="remise_percent" value="'.$commande->remise_percent.'">'."\n";
|
||||
|
||||
print '<tr><td>'.$langs->trans("Order").'</td><td colspan="2">'.$commande->ref.'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("TotalHT").'</td><td colspan="2">'.price($commande->total_ht).'</td></tr>';
|
||||
@ -626,18 +670,22 @@ if ($_GET["action"] == 'create')
|
||||
}
|
||||
elseif ($_GET["contratid"] > 0)
|
||||
{
|
||||
$amount = ($obj->price);
|
||||
print '<input type="hidden" name="amount" value="'.$amount.'">'."\n";
|
||||
print '<input type="hidden" name="total" value="'.$obj->total.'">'."\n";
|
||||
print '<input type="hidden" name="remise" value="'.$obj->remise.'">'."\n";
|
||||
print '<input type="hidden" name="remise_percent" value="'.$obj->remise_percent.'">'."\n";
|
||||
print '<input type="hidden" name="tva" value="'.$obj->tva.'">'."\n";
|
||||
// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
|
||||
$contrat->remise=0;
|
||||
$contrat->remise_percent=$soc->remise_client;
|
||||
$contrat->update_price();
|
||||
|
||||
print '<input type="hidden" name="amount" value="'.$contrat->total_ht.'">'."\n";
|
||||
print '<input type="hidden" name="total" value="'.$contrat->total_ttc.'">'."\n";
|
||||
print '<input type="hidden" name="remise" value="'.$contrat->remise.'">'."\n";
|
||||
print '<input type="hidden" name="remise_percent" value="'.$contrat->remise_percent.'">'."\n";
|
||||
print '<input type="hidden" name="tva" value="'.$contrat->total_tva.'">'."\n";
|
||||
print '<input type="hidden" name="contratid" value="'.$_GET["contratid"].'">';
|
||||
|
||||
print '<tr><td>'.$langs->trans("Contract").'</td><td colspan="2">'.$obj->ref.'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("TotalHT").'</td><td colspan="2">'.price($amount).'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("VAT").'</td><td colspan="2">'.price($obj->tva)."</td></tr>";
|
||||
print '<tr><td>'.$langs->trans("TotalTTC").'</td><td colspan="2">'.price($obj->total)."</td></tr>";
|
||||
print '<tr><td>'.$langs->trans("Contract").'</td><td colspan="2">'.$contrat->ref.'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("TotalHT").'</td><td colspan="2">'.price($contrat->total_ht).'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("VAT").'</td><td colspan="2">'.price($contrat->total_tva)."</td></tr>";
|
||||
print '<tr><td>'.$langs->trans("TotalTTC").'</td><td colspan="2">'.price($contrat->total_ttc)."</td></tr>";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -677,7 +725,7 @@ if ($_GET["action"] == 'create')
|
||||
/*
|
||||
* Factures récurrentes
|
||||
*/
|
||||
if ($_GET["propalid"] == 0 && $_GET["commandeid"] == 0)
|
||||
if ($_GET["propalid"] == 0 && $_GET["commandeid"] == 0 && $_GET["contratid"] == 0)
|
||||
{
|
||||
$sql = "SELECT r.rowid, r.titre, r.amount FROM ".MAIN_DB_PREFIX."facture_rec as r";
|
||||
$sql .= " WHERE r.fk_soc = ".$soc->id;
|
||||
@ -718,7 +766,9 @@ if ($_GET["action"] == 'create')
|
||||
print_titre($langs->trans("ProductsAndServices"));
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Description").'</td>';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Ref").'</td>';
|
||||
print '<td>'.$langs->trans("Description").'</td>';
|
||||
print '<td align="right">'.$langs->trans("VAT").'</td>';
|
||||
print '<td align="right">'.$langs->trans("PriceUHT").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Qty").'</td>';
|
||||
@ -760,7 +810,7 @@ if ($_GET["action"] == 'create')
|
||||
$sql = "SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.price, pt.qty, pt.remise_percent";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt ";
|
||||
$sql .= " WHERE pt.fk_propal = ".$_GET["propalid"];
|
||||
$sql .= " AND pt.fk_product = 0";
|
||||
$sql .= " AND (pt.fk_product = 0 or pt.fk_product is null)";
|
||||
$sql .= " ORDER BY pt.rowid ASC";
|
||||
$result=$db->query($sql);
|
||||
if ($result)
|
||||
@ -772,7 +822,7 @@ if ($_GET["action"] == 'create')
|
||||
$objp = $db->fetch_object($result);
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]><td> </td>\n";
|
||||
print '<td>'.$objp->product.'</td>';
|
||||
print '<td>'.dolibarr_trunc($objp->product,60).'</td>';
|
||||
print '<td align="right">'.$objp->tva_tx.'%</td>';
|
||||
print '<td align="right">'.price($objp->price).'</td>';
|
||||
print '<td align="right">'.$objp->qty.'</td>';
|
||||
@ -792,26 +842,33 @@ if ($_GET["action"] == 'create')
|
||||
// Si creation depuis une commande
|
||||
if ($_GET["commandeid"])
|
||||
{
|
||||
print '<br>';
|
||||
print_titre($langs->trans("Products"));
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Product").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Price").'</td><td align="center">'.$langs->trans("Discount").'</td><td align="center">'.$langs->trans("Qty").'</td></tr>';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Ref").'</td>';
|
||||
print '<td>'.$langs->trans("Description").'</td>';
|
||||
print '<td align="right">'.$langs->trans("VAT").'</td>';
|
||||
print '<td align="right">'.$langs->trans("PriceUHT").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Qty").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Discount").'</td></tr>';
|
||||
|
||||
$sql = "SELECT pt.rowid, p.label as product, p.ref, pt.subprice, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pt, ".MAIN_DB_PREFIX."product as p";
|
||||
$sql .= " WHERE pt.fk_product = p.rowid AND pt.fk_commande = ".$commande->id;
|
||||
$sql .= " ORDER BY pt.rowid ASC";
|
||||
$sql = "SELECT pt.rowid, pt.subprice, pt.tva_tx, pt.qty, pt.remise_percent, pt.description,";
|
||||
$sql.= " p.label as product, p.ref, p.rowid as prodid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as pt, ".MAIN_DB_PREFIX."product as p";
|
||||
$sql.= " WHERE pt.fk_product = p.rowid AND pt.fk_commande = ".$commande->id;
|
||||
$sql.= " ORDER BY pt.rowid ASC";
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows();
|
||||
$num = $db->num_rows($result);
|
||||
$i = 0;
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object();
|
||||
$objp = $db->fetch_object($result);
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td><a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->prodid.'">'.img_object($langs->trans(""),"product")." ".$objp->ref."</a>";
|
||||
print $objp->product?' - '.$objp->product:'';
|
||||
@ -819,9 +876,11 @@ if ($_GET["action"] == 'create')
|
||||
print '<td>';
|
||||
print dolibarr_trunc($objp->description,60);
|
||||
print '</td>';
|
||||
print '<td align="right">'.$objp->tva_tx.'%</td>';
|
||||
print '<td align="right">'.price($objp->subprice).'</td>';
|
||||
print '<td align="center">'.$objp->remise_percent.'%</td>';
|
||||
print '<td align="center">'.$objp->qty.'</td></tr>';
|
||||
print '<td align="right">'.$objp->qty.'</td>';
|
||||
print '<td align="right">'.$objp->remise_percent.'%</td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
@ -830,10 +889,10 @@ if ($_GET["action"] == 'create')
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
// Lignes de commande non produits prédéfinis
|
||||
$sql = "SELECT pt.rowid, pt.description as product, pt.subprice, pt.qty, pt.remise_percent";
|
||||
$sql = "SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.subprice, pt.qty, pt.remise_percent";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pt";
|
||||
$sql .= " WHERE pt.fk_commande = ".$commande->id;
|
||||
$sql .= " AND pt.fk_product = 0";
|
||||
$sql .= " AND (pt.fk_product = 0 or pt.fk_product is null)";
|
||||
$sql .= " ORDER BY pt.rowid ASC";
|
||||
|
||||
$result=$db->query($sql);
|
||||
@ -846,10 +905,11 @@ if ($_GET["action"] == 'create')
|
||||
$objp = $db->fetch_object($result);
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]><td> </td>\n";
|
||||
print '<td>'.$objp->product.'</td>';
|
||||
print '<td>'.dolibarr_trunc($objp->product,60).'</td>';
|
||||
print '<td align="right">'.$objp->tva_tx.'%</td>';
|
||||
print '<td align="right">'.price($objp->subprice).'</td>';
|
||||
print '<td align="center">'.$objp->remise_percent.'%</td>';
|
||||
print '<td align="center">'.$objp->qty.'</td>';
|
||||
print '<td align="right">'.$objp->qty.'</td>';
|
||||
print '<td align="right">'.$objp->remise_percent.'%</td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
@ -861,7 +921,90 @@ if ($_GET["action"] == 'create')
|
||||
|
||||
print '</table>';
|
||||
}
|
||||
|
||||
|
||||
// Si creation depuis un contrat
|
||||
if ($_GET["contratid"])
|
||||
{
|
||||
print '<br>';
|
||||
print_titre($langs->trans("Services"));
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Ref").'</td>';
|
||||
print '<td>'.$langs->trans("Description").'</td>';
|
||||
print '<td align="right">'.$langs->trans("VAT").'</td>';
|
||||
print '<td align="right">'.$langs->trans("PriceUHT").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Qty").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Discount").'</td></tr>';
|
||||
|
||||
$sql = "SELECT pt.rowid, pt.subprice, pt.tva_tx, pt.qty, pt.remise_percent, pt.description,";
|
||||
$sql.= " p.label as product, p.ref, p.rowid as prodid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as pt, ".MAIN_DB_PREFIX."product as p";
|
||||
$sql.= " WHERE pt.fk_product = p.rowid AND pt.fk_contrat = ".$contrat->id;
|
||||
$sql.= " ORDER BY pt.rowid ASC";
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows($result);
|
||||
$i = 0;
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($result);
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td><a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->prodid.'">'.img_object($langs->trans(""),"service")." ".$objp->ref."</a>";
|
||||
print $objp->product?' - '.$objp->product:'';
|
||||
print "</td>\n";
|
||||
print '<td>';
|
||||
print dolibarr_trunc($objp->description,60);
|
||||
print '</td>';
|
||||
print '<td align="right">'.$objp->tva_tx.'%</td>';
|
||||
print '<td align="right">'.price($objp->subprice).'</td>';
|
||||
print '<td align="right">'.$objp->qty.'</td>';
|
||||
print '<td align="right">'.$objp->remise_percent.'%</td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
// Lignes de contrat non produits prédéfinis
|
||||
$sql = "SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.subprice, pt.qty, pt.remise_percent";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contratdet as pt";
|
||||
$sql .= " WHERE pt.fk_contrat = ".$contrat->id;
|
||||
$sql .= " AND (pt.fk_product = 0 or pt.fk_product is null)";
|
||||
$sql .= " ORDER BY pt.rowid ASC";
|
||||
|
||||
$result=$db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows($result);
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($result);
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]><td> </td>\n";
|
||||
print '<td>'.dolibarr_trunc($objp->product,60).'</td>';
|
||||
print '<td align="right">'.$objp->tva_tx.'%</td>';
|
||||
print '<td align="right">'.price($objp->subprice).'</td>';
|
||||
print '<td align="right">'.$objp->qty.'</td>';
|
||||
print '<td align="right">'.$objp->remise_percent.'%</td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -216,8 +216,8 @@ class Contrat
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Charge de la base les données du contrat
|
||||
* \param id id du contrat à charger
|
||||
* \brief Chargement depuis la base des données du contrat
|
||||
* \param id Id du contrat à charger
|
||||
* \return int <0 si KO, >0 si OK
|
||||
*/
|
||||
function fetch($id)
|
||||
@ -257,17 +257,113 @@ class Contrat
|
||||
$this->societe->fetch($result["fk_soc"]);
|
||||
|
||||
$this->db->free($resql);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("Contrat::Fetch Erreur lecture contrat");
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reinitialise le tableau lignes
|
||||
*/
|
||||
function fetch_lignes()
|
||||
{
|
||||
$this->lignes = array();
|
||||
|
||||
/*
|
||||
* Lignes contrats liées à un produit
|
||||
*/
|
||||
$sql = "SELECT d.description, p.rowid, p.label, p.description as product_desc, p.ref,";
|
||||
$sql.= " d.price_ht, d.tva_tx, d.qty, d.remise_percent, d.subprice";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as d, ".MAIN_DB_PREFIX."product as p";
|
||||
$sql.= " WHERE d.fk_contrat = ".$this->id ." AND d.fk_product = p.rowid";
|
||||
$sql.= " ORDER by d.rowid ASC";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $this->db->fetch_object($result);
|
||||
|
||||
$ligne = new ContratLigne();
|
||||
$ligne->desc = stripslashes($objp->description); // Description ligne
|
||||
$ligne->libelle = stripslashes($objp->label); // Label produit
|
||||
$ligne->product_desc = stripslashes($objp->product_desc); // Description produit
|
||||
$ligne->qty = $objp->qty;
|
||||
$ligne->ref = $objp->ref;
|
||||
$ligne->tva_tx = $objp->tva_tx;
|
||||
$ligne->subprice = $objp->subprice;
|
||||
$ligne->remise_percent = $objp->remise_percent;
|
||||
$ligne->price = $objp->price;
|
||||
$ligne->product_id = $objp->rowid;
|
||||
|
||||
$this->lignes[$i] = $ligne;
|
||||
//dolibarr_syslog("1 ".$ligne->desc);
|
||||
//dolibarr_syslog("2 ".$ligne->product_desc);
|
||||
$i++;
|
||||
}
|
||||
$this->db->free($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("Contrat::Fetch Erreur lecture des lignes de contrats liées aux produits");
|
||||
return -3;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lignes contrat liées à aucun produit
|
||||
*/
|
||||
$sql = "SELECT d.qty, d.description, d.price_ht, d.subprice, d.tva_tx, d.rowid, d.remise_percent";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contratdet as d";
|
||||
$sql .= " WHERE d.fk_contrat = ".$this->id ." AND d.fk_product = 0";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows($result);
|
||||
$j = 0;
|
||||
|
||||
while ($j < $num)
|
||||
{
|
||||
$objp = $this->db->fetch_object($result);
|
||||
$ligne = new PropaleLigne();
|
||||
$ligne->libelle = stripslashes($objp->description);
|
||||
$ligne->desc = stripslashes($objp->description);
|
||||
$ligne->qty = $objp->qty;
|
||||
$ligne->ref = $objp->ref;
|
||||
$ligne->tva_tx = $objp->tva_tx;
|
||||
$ligne->subprice = $objp->subprice;
|
||||
$ligne->remise_percent = $objp->remise_percent;
|
||||
$ligne->price = $objp->price;
|
||||
$ligne->product_id = 0;
|
||||
|
||||
$this->lignes[$i] = $ligne;
|
||||
$i++;
|
||||
$j++;
|
||||
}
|
||||
|
||||
$this->db->free($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("Contrat::Fetch Erreur lecture des lignes de contrat non liées aux produits");
|
||||
$this->error=$this->db->error();
|
||||
return -2;
|
||||
}
|
||||
|
||||
return $this->lignes;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Crée un contrat vierge en base
|
||||
* \param user Utilisateur qui crée
|
||||
@ -372,54 +468,60 @@ class Contrat
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$qty = ereg_replace(",",".",$qty);
|
||||
$pu = ereg_replace(",",".",$pu);
|
||||
|
||||
dolibarr_syslog("Contrat::AddLine $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $datestart, $dateend");
|
||||
dolibarr_syslog("contrat.class.php::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent, $datestart, $dateend");
|
||||
|
||||
if ($fk_product > 0)
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
$prod = new Product($this->db, $fk_product);
|
||||
if ($prod->fetch($fk_product) > 0)
|
||||
$qty = ereg_replace(",",".",$qty);
|
||||
$pu = ereg_replace(",",".",$pu);
|
||||
|
||||
if ($fk_product > 0)
|
||||
{
|
||||
$label = $prod->libelle;
|
||||
$pu = $prod->price;
|
||||
$txtva = $prod->tva_tx;
|
||||
$prod = new Product($this->db, $fk_product);
|
||||
if ($prod->fetch($fk_product) > 0)
|
||||
{
|
||||
$label = $prod->libelle;
|
||||
$pu = $prod->price;
|
||||
$txtva = $prod->tva_tx;
|
||||
}
|
||||
}
|
||||
|
||||
$remise = 0;
|
||||
$price = ereg_replace(",",".",round($pu, 2));
|
||||
$subprice = $price;
|
||||
if (strlen($remise_percent) > 0)
|
||||
{
|
||||
$remise = round(($pu * $remise_percent / 100), 2);
|
||||
$price = $pu - $remise;
|
||||
}
|
||||
|
||||
// Insertion dans la base
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet";
|
||||
$sql.= " (fk_contrat, label, description, fk_product, price_ht, qty, tva_tx,";
|
||||
$sql.= " remise_percent, subprice, remise";
|
||||
if ($datestart > 0) { $sql.= ",date_ouverture_prevue"; }
|
||||
if ($dateend > 0) { $sql.= ",date_fin_validite"; }
|
||||
$sql.= ") VALUES ($this->id, '" . addslashes($label) . "','" . addslashes($desc) . "',";
|
||||
$sql.= ($fk_product>0 ? $fk_product : "null");
|
||||
$sql.= ",".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."'";
|
||||
if ($datestart > 0) { $sql.= ",".$this->db->idate($datestart); }
|
||||
if ($dateend > 0) { $sql.= ",".$this->db->idate($dateend); }
|
||||
$sql.= ");";
|
||||
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
$this->update_price();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
$remise = 0;
|
||||
$price = ereg_replace(",",".",round($pu, 2));
|
||||
$subprice = $price;
|
||||
if (strlen($remise_percent) > 0)
|
||||
{
|
||||
$remise = round(($pu * $remise_percent / 100), 2);
|
||||
$price = $pu - $remise;
|
||||
}
|
||||
|
||||
// Insertion dans la base
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet";
|
||||
$sql.= " (fk_contrat, label, description, fk_product, price_ht, qty, tva_tx,";
|
||||
$sql.= " remise_percent, subprice, remise";
|
||||
if ($datestart > 0) { $sql.= ",date_ouverture_prevue"; }
|
||||
if ($dateend > 0) { $sql.= ",date_fin_validite"; }
|
||||
$sql.= ") VALUES ($this->id, '" . addslashes($label) . "','" . addslashes($desc) . "',";
|
||||
$sql.= ($fk_product>0 ? $fk_product : "null");
|
||||
$sql.= ",".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."'";
|
||||
if ($datestart > 0) { $sql.= ",".$this->db->idate($datestart); }
|
||||
if ($dateend > 0) { $sql.= ",".$this->db->idate($dateend); }
|
||||
$sql.= ");";
|
||||
|
||||
// Retour
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
//$this->update_price();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return -1;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -437,80 +539,161 @@ class Contrat
|
||||
*/
|
||||
function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $datestart='', $dateend='', $tvatx)
|
||||
{
|
||||
// Nettoyage parametres
|
||||
$qty=trim($qty);
|
||||
$desc=trim($desc);
|
||||
$desc=trim($desc);
|
||||
$price = ereg_replace(",",".",$pu);
|
||||
$tvatx = ereg_replace(",",".",$tvatx);
|
||||
$subprice = $price;
|
||||
$remise = 0;
|
||||
if (strlen($remise_percent) > 0)
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
$remise = round(($pu * $remise_percent / 100), 2);
|
||||
$price = $pu - $remise;
|
||||
}
|
||||
else
|
||||
{
|
||||
$remise_percent=0;
|
||||
}
|
||||
|
||||
dolibarr_syslog("Contrat::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $datestart, $dateend, $tvatx");
|
||||
// Nettoyage parametres
|
||||
$qty=trim($qty);
|
||||
$desc=trim($desc);
|
||||
$desc=trim($desc);
|
||||
$price = ereg_replace(",",".",$pu);
|
||||
$tvatx = ereg_replace(",",".",$tvatx);
|
||||
$subprice = $price;
|
||||
$remise = 0;
|
||||
if (strlen($remise_percent) > 0)
|
||||
{
|
||||
$remise = round(($pu * $remise_percent / 100), 2);
|
||||
$price = $pu - $remise;
|
||||
}
|
||||
else
|
||||
{
|
||||
$remise_percent=0;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet set description='".addslashes($desc)."'";
|
||||
$sql .= ",price_ht='" . ereg_replace(",",".",$price)."'";
|
||||
$sql .= ",subprice='" . ereg_replace(",",".",$subprice)."'";
|
||||
$sql .= ",remise='" . ereg_replace(",",".",$remise)."'";
|
||||
$sql .= ",remise_percent='".ereg_replace(",",".",$remise_percent)."'";
|
||||
$sql .= ",qty='$qty'";
|
||||
$sql .= ",tva_tx='". ereg_replace(",",".",$tvatx)."'";
|
||||
|
||||
if ($datestart > 0) { $sql.= ",date_ouverture_prevue=".$this->db->idate($datestart); }
|
||||
else { $sql.=",date_ouverture_prevue=null"; }
|
||||
if ($dateend > 0) { $sql.= ",date_fin_validite=".$this->db->idate($dateend); }
|
||||
else { $sql.=",date_fin_validite=null"; }
|
||||
|
||||
$sql .= " WHERE rowid = $rowid ;";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$this->db->commit();
|
||||
|
||||
return $result;
|
||||
dolibarr_syslog("Contrat::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $datestart, $dateend, $tvatx");
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet set description='".addslashes($desc)."'";
|
||||
$sql .= ",price_ht='" . ereg_replace(",",".",$price)."'";
|
||||
$sql .= ",subprice='" . ereg_replace(",",".",$subprice)."'";
|
||||
$sql .= ",remise='" . ereg_replace(",",".",$remise)."'";
|
||||
$sql .= ",remise_percent='".ereg_replace(",",".",$remise_percent)."'";
|
||||
$sql .= ",qty='$qty'";
|
||||
$sql .= ",tva_tx='". ereg_replace(",",".",$tvatx)."'";
|
||||
|
||||
if ($datestart > 0) { $sql.= ",date_ouverture_prevue=".$this->db->idate($datestart); }
|
||||
else { $sql.=",date_ouverture_prevue=null"; }
|
||||
if ($dateend > 0) { $sql.= ",date_fin_validite=".$this->db->idate($dateend); }
|
||||
else { $sql.=",date_fin_validite=null"; }
|
||||
|
||||
$sql .= " WHERE rowid = $rowid ;";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$this->update_price();
|
||||
|
||||
$this->db->commit();
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->error=$this->db->error();
|
||||
dolibarr_syslog("Contrat::UpdateLigne Erreur -1");
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
dolibarr_syslog("Contrat::UpdateLigne Erreur -2 Contrat en mode incompatible pour cette action");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Supprime une ligne de detail
|
||||
* \param idligne Id de la ligne detail à supprimer
|
||||
* \return int >0 si ok, <0 si ko
|
||||
*/
|
||||
function delete_line($idligne)
|
||||
{
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet WHERE rowid =".$idligne;
|
||||
|
||||
if ($this->db->query($sql) )
|
||||
{
|
||||
$this->update_price();
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
dolibarr_print_error($this->db);
|
||||
|
||||
/**
|
||||
* \brief Mets à jour le prix total du contrat
|
||||
*/
|
||||
|
||||
function update_price()
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
|
||||
|
||||
/*
|
||||
* Liste des produits a ajouter
|
||||
*/
|
||||
$sql = "SELECT price_ht, qty, tva_tx";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet";
|
||||
$sql.= " WHERE fk_contrat = ".$this->id;
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$products[$i][0] = $obj->price_ht;
|
||||
$products[$i][1] = $obj->qty;
|
||||
$products[$i][2] = $obj->tva_tx;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
$calculs = calcul_price($products, $this->remise_percent);
|
||||
|
||||
$this->remise = $calculs[3];
|
||||
$this->total_ht = $calculs[0];
|
||||
$this->total_tva = $calculs[1];
|
||||
$this->total_ttc = $calculs[2];
|
||||
|
||||
/*
|
||||
// Met a jour en base
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET";
|
||||
$sql .= " price='". ereg_replace(",",".",$this->total_ht)."'";
|
||||
$sql .= ", tva='". ereg_replace(",",".",$this->total_tva)."'";
|
||||
$sql .= ", total='". ereg_replace(",",".",$this->total_ttc)."'";
|
||||
$sql .= ", remise='".ereg_replace(",",".",$this->remise)."'";
|
||||
$sql .=" WHERE rowid = $this->id";
|
||||
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Supprime une ligne de detail du contrat
|
||||
* \param idligne id de la ligne detail de contrat à supprimer
|
||||
*/
|
||||
function delete_line($idligne)
|
||||
{
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet WHERE rowid =".$idligne;
|
||||
|
||||
if ($this->db->query($sql) )
|
||||
{
|
||||
//$this->update_price();
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Classe le contrat dans un projet
|
||||
@ -879,4 +1062,19 @@ class Contrat
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\class ContratLigne
|
||||
\brief Classe permettant la gestion des lignes de contrats
|
||||
*/
|
||||
|
||||
class ContratLigne
|
||||
{
|
||||
function ContratLigne()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@ -149,7 +149,7 @@ if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer)
|
||||
if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer && $_POST["save"])
|
||||
{
|
||||
$contrat = new Contrat($db,"",$_GET["id"]);
|
||||
if ($contrat->fetch($_GET["id"]))
|
||||
@ -179,6 +179,11 @@ if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer)
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer && $_POST["cancel"])
|
||||
{
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
}
|
||||
|
||||
if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer)
|
||||
{
|
||||
$contrat = new Contrat($db);
|
||||
@ -595,10 +600,12 @@ else
|
||||
*/
|
||||
echo '<br><table class="noborder" width="100%">';
|
||||
|
||||
$sql = "SELECT cd.statut, cd.label, cd.fk_product, cd.description, cd.price_ht, cd.qty, cd.rowid, cd.tva_tx, cd.remise_percent, cd.subprice,";
|
||||
$sql = "SELECT cd.statut, cd.label as label_det, cd.fk_product, cd.description, cd.price_ht, cd.qty, cd.rowid, cd.tva_tx, cd.remise_percent, cd.subprice,";
|
||||
$sql.= " ".$db->pdate("cd.date_ouverture_prevue")." as date_debut, ".$db->pdate("cd.date_ouverture")." as date_debut_reelle,";
|
||||
$sql.= " ".$db->pdate("cd.date_fin_validite")." as date_fin, ".$db->pdate("cd.date_cloture")." as date_fin_reelle";
|
||||
$sql.= " ".$db->pdate("cd.date_fin_validite")." as date_fin, ".$db->pdate("cd.date_cloture")." as date_fin_reelle,";
|
||||
$sql.= " p.ref, p.label";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
|
||||
$sql.= " WHERE cd.fk_contrat = ".$id;
|
||||
$sql.= " ORDER BY cd .rowid";
|
||||
|
||||
@ -635,7 +642,8 @@ else
|
||||
{
|
||||
print '<td>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">';
|
||||
print img_object($langs->trans("ShowService"),"service").' '.$objp->label.'</a>';
|
||||
print img_object($langs->trans("ShowService"),"service").' '.$objp->ref.'</a>';
|
||||
print $objp->label?' - '.$objp->label:'';
|
||||
if ($objp->description) print '<br />'.stripslashes(nl2br($objp->description));
|
||||
print '</td>';
|
||||
}
|
||||
@ -740,10 +748,16 @@ else
|
||||
// Ligne carac
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">';
|
||||
if ($objp->label)
|
||||
if ($objp->fk_product)
|
||||
{
|
||||
print img_object($langs->trans("ShowService"),"service").' '.$objp->label.'</a><br>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">';
|
||||
print img_object($langs->trans("ShowService"),"service").' '.$objp->ref.'</a>';
|
||||
print $objp->label?' - '.$objp->label:'';
|
||||
print '</br>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $objp->label?$objp->label.'<br>':'';
|
||||
}
|
||||
print '<textarea name="eldesc" cols="60" rows="1">'.$objp->description.'</textarea></td>';
|
||||
print '<td align="right">';
|
||||
@ -752,10 +766,12 @@ else
|
||||
print '<td align="right"><input size="6" type="text" name="elprice" value="'.price($objp->subprice).'"></td>';
|
||||
print '<td align="center"><input size="3" type="text" name="elqty" value="'.$objp->qty.'"></td>';
|
||||
print '<td align="right"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.'">%</td>';
|
||||
print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
|
||||
print '<td align="center" colspan="3" rowspan="2" valign="middle"><input type="submit" class="button" name="save" value="'.$langs->trans("Modify").'">';
|
||||
print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
print '</td>';
|
||||
// Ligne dates prévues
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td colspan="8">';
|
||||
print '<td colspan="5">';
|
||||
print $langs->trans("DateStartPlanned").' ';
|
||||
$html->select_date($objp->date_debut,"date_start_update",0,0,($objp->date_debut>0?0:1));
|
||||
print ' '.$langs->trans("DateEndPlanned").' ';
|
||||
@ -792,6 +808,7 @@ else
|
||||
|
||||
$var=false;
|
||||
|
||||
// Service sur produit prédéfini
|
||||
print '<form action="fiche.php?id='.$id.'" method="post">';
|
||||
print '<input type="hidden" name="action" value="addligne">';
|
||||
print '<input type="hidden" name="mode" value="predefined">';
|
||||
@ -799,7 +816,8 @@ else
|
||||
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td colspan="3">';
|
||||
$html->select_produits('','p_idprod','',0);
|
||||
$html->select_produits('','p_idprod','',0).'<br>';
|
||||
print '<textarea name="desc" cols="50" rows="1"></textarea>';
|
||||
print '</td>';
|
||||
|
||||
print '<td align="center"><input type="text" class="flat" size="2" name="pqty" value="1"></td>';
|
||||
@ -819,6 +837,7 @@ else
|
||||
|
||||
$var=!$var;
|
||||
|
||||
// Service libre
|
||||
print '<form action="fiche.php?id='.$id.'" method="post">';
|
||||
print '<input type="hidden" name="action" value="addligne">';
|
||||
print '<input type="hidden" name="mode" value="libre">';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user