New: Ajout gestion remise/avoirs sur les propales

This commit is contained in:
Laurent Destailleur 2006-04-08 11:39:41 +00:00
parent 74fd3687d0
commit fc0508f8d6
5 changed files with 292 additions and 128 deletions

View File

@ -97,7 +97,7 @@ if ($_GET["action"] == 'create')
print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" value="'.$numpr.'"></td></tr>'; print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" value="'.$numpr.'"></td></tr>';
// Societe // Societe
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">'.$soc->nom_url; print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">'.img_object($langs->trans("ShowCompany"),'company').' '.$soc->nom_url;
print '<input type="hidden" name="socidp" value="'.$soc->id.'">'; print '<input type="hidden" name="socidp" value="'.$soc->id.'">';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';

View File

@ -82,7 +82,7 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')
$propalid = 0; $propalid = 0;
$brouillon = 1; $brouillon = 1;
} }
Header('Location: propal.php'); Header('Location: '.$_SERVER["PHP_SELF"]);
exit; exit;
} }
@ -96,7 +96,7 @@ if ($_POST['action'] == 'confirm_validate' && $_POST['confirm'] == 'yes')
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
$result=$propal->valid($user); $result=$propal->valid($user);
} }
Header ('Location: propal.php?propalid='.$_GET['propalid']); Header ('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$_GET['propalid']);
exit; exit;
} }
@ -135,6 +135,8 @@ if ($_POST['action'] == 'add')
$propal->duree_validite = $_POST['duree_validite']; $propal->duree_validite = $_POST['duree_validite'];
$propal->cond_reglement_id = $_POST['cond_reglement_id']; $propal->cond_reglement_id = $_POST['cond_reglement_id'];
$propal->mode_reglement_id = $_POST['mode_reglement_id']; $propal->mode_reglement_id = $_POST['mode_reglement_id'];
$propal->remise_percent = $_POST['remise_percent'];
$propal->remise_absolue = $_POST['remise_absolue'];
$propal->socidp = $_POST['socidp']; $propal->socidp = $_POST['socidp'];
$propal->contactid = $_POST['contactidp']; $propal->contactid = $_POST['contactidp'];
$propal->projetidp = $_POST['projetidp']; $propal->projetidp = $_POST['projetidp'];
@ -182,7 +184,7 @@ if ($_POST['action'] == 'add')
{ {
propale_pdf_create($db, $id, $_POST['model']); propale_pdf_create($db, $id, $_POST['model']);
Header ('Location: propal.php?propalid='.$id); Header ('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$id);
exit; exit;
} }
else else
@ -266,7 +268,7 @@ if ($_POST['action'] == 'send')
$filename[1] = $_FILES['addedfile']['name']; $filename[1] = $_FILES['addedfile']['name'];
$mimetype[1] = $_FILES['addedfile']['type']; $mimetype[1] = $_FILES['addedfile']['type'];
} }
// Envoi de la facture // Envoi de la propal
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc); $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc);
if ($mailfile->sendfile()) if ($mailfile->sendfile())
{ {
@ -291,7 +293,7 @@ if ($_POST['action'] == 'send')
else else
{ {
// Renvoie sur la fiche // Renvoie sur la fiche
Header('Location: propal.php?propalid='.$propal->id.'&msg='.urlencode($msg)); Header('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&msg='.urlencode($msg));
exit; exit;
} }
} }
@ -433,6 +435,22 @@ if ($_POST["action"] == 'setconditions')
if ($resql < 0) dolibarr_print_error($db); if ($resql < 0) dolibarr_print_error($db);
} }
if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->propale->creer)
{
$propal = new Propal($db);
$propal->fetch($_REQUEST['propalid']);
$result = $propal->set_remise_percent($user, $_POST['remise_percent']);
$_GET['propalid']=$_REQUEST['propalid'];
}
if ($_REQUEST['action'] == 'setremiseabsolue' && $user->rights->propale->creer)
{
$propal = new Propal($db);
$propal->fetch($_REQUEST['propalid']);
$result = $propal->set_remise_absolue($user, $_POST['remise_absolue']);
$_GET['propalid']=$_REQUEST['propalid'];
}
// Mode de règlement // Mode de règlement
if ($_POST["action"] == 'setmode') if ($_POST["action"] == 'setmode')
{ {
@ -501,7 +519,7 @@ if ($_GET['propalid'] > 0)
*/ */
if ($_GET['action'] == 'delete') if ($_GET['action'] == 'delete')
{ {
$html->form_confirm('propal.php?propalid='.$propal->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp'), 'confirm_delete'); $html->form_confirm($_SERVER["PHP_SELF"].'?propalid='.$propal->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp'), 'confirm_delete');
print '<br>'; print '<br>';
} }
@ -510,7 +528,7 @@ if ($_GET['propalid'] > 0)
*/ */
if ($_GET['action'] == 'validate') if ($_GET['action'] == 'validate')
{ {
$html->form_confirm('propal.php?propalid='.$propal->id, $langs->trans('ValidateProp'), $langs->trans('ConfirmValidateProp'), 'confirm_validate'); $html->form_confirm($_SERVER["PHP_SELF"].'?propalid='.$propal->id, $langs->trans('ValidateProp'), $langs->trans('ConfirmValidateProp'), 'confirm_validate');
print '<br>'; print '<br>';
} }
@ -702,7 +720,7 @@ if ($_GET['propalid'] > 0)
if ($propal->statut == 0 && $user->rights->propale->creer) if ($propal->statut == 0 && $user->rights->propale->creer)
{ {
print '<td colspan="2">'; print '<td colspan="2">';
print '<form action="propal.php?propalid='.$propal->id.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'" method="post">';
print '<input type="hidden" name="action" value="set_project">'; print '<input type="hidden" name="action" value="set_project">';
$form->select_projects($societe->id, $propal->projetidp, 'projetidp'); $form->select_projects($societe->id, $propal->projetidp, 'projetidp');
print '</td><td>'; print '</td><td>';
@ -730,31 +748,6 @@ if ($_GET['propalid'] > 0)
print '</tr>'; print '</tr>';
} }
// Remise globale
/* TODO Remise a mettre sur meme principe que factures
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('GlobalDiscount');
print '</td>';
if ($_GET['action'] != 'editdiscount' && $propal->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdiscount&amp;propalid='.$propal->id.'">'.img_edit($langs->trans('SetGlobalDiscount'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($_GET['action'] == 'editdiscount' && $propal->brouillon == 1 && $user->rights->propale->creer)
{
print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
print '<input type="hidden" name="action" value="set_discount">';
print '<input type="text" name="remise" size="3" value="'.$propal->remise_percent.'">% ';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print ' <a href="propal/aideremise.php?propalid='.$propal->id.'">?</a>';
print '</form>';
}
else
{
print $propal->remise_percent.'%';
}
print '</td></tr>';
*/
// Amount // Amount
print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>'; print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>';
print '<td align="right" colspan="2"><b>'.price($propal->price).'</b></td>'; print '<td align="right" colspan="2"><b>'.price($propal->price).'</b></td>';
@ -799,6 +792,7 @@ if ($_GET['propalid'] > 0)
print '<td align="right" width="50">'.$langs->trans('AmountHT').'</td>'; print '<td align="right" width="50">'.$langs->trans('AmountHT').'</td>';
print '<td width="16">&nbsp;</td>'; print '<td width="16">&nbsp;</td>';
print '<td width="16">&nbsp;</td>'; print '<td width="16">&nbsp;</td>';
print '<td width="16">&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
} }
$var=true; $var=true;
@ -872,16 +866,19 @@ if ($_GET['propalid'] > 0)
// Icone d'edition et suppression // Icone d'edition et suppression
if ($propal->statut == 0 && $user->rights->propale->creer) if ($propal->statut == 0 && $user->rights->propale->creer)
{ {
print '<td align="right"><a href="propal.php?propalid='.$propal->id.'&amp;action=editline&amp;ligne='.$objp->rowid.'">'; print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=editline&amp;ligne='.$objp->rowid.'">';
print img_edit(); print img_edit();
print '</a></td>'; print '</a></td>';
print '<td align="right"><a href="propal.php?propalid='.$propal->id.'&amp;action=del_ligne&amp;ligne='.$objp->rowid.'">'; print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=del_ligne&amp;ligne='.$objp->rowid.'">';
print img_delete(); print img_delete();
print '</a></td>'; print '</a></td>';
} print '<td align="right">';
print '&nbsp;'; // \todo Mettre critere ordre
print '</td>';
}
else else
{ {
print '<td>&nbsp;</td><td>&nbsp;</td>'; print '<td colspan="3">&nbsp;</td>';
} }
print '</tr>'; print '</tr>';
} }
@ -889,7 +886,7 @@ if ($_GET['propalid'] > 0)
// Ligne en mode update // Ligne en mode update
if ($propal->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["ligne"] == $objp->rowid) if ($propal->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["ligne"] == $objp->rowid)
{ {
print '<form action="propal.php?propalid='.$propal->id.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'" method="post">';
print '<input type="hidden" name="action" value="updateligne">'; print '<input type="hidden" name="action" value="updateligne">';
print '<input type="hidden" name="propalid" value="'.$propal->id.'">'; print '<input type="hidden" name="propalid" value="'.$propal->id.'">';
print '<input type="hidden" name="ligne" value="'.$_GET["ligne"].'">'; print '<input type="hidden" name="ligne" value="'.$_GET["ligne"].'">';
@ -914,7 +911,7 @@ if ($_GET['propalid'] > 0)
print '<td align="right"><input size="6" type="text" name="subprice" value="'.price($objp->subprice).'"></td>'; print '<td align="right"><input size="6" type="text" name="subprice" value="'.price($objp->subprice).'"></td>';
print '<td align="right"><input size="2" type="text" name="qty" value="'.$objp->qty.'"></td>'; print '<td align="right"><input size="2" type="text" name="qty" value="'.$objp->qty.'"></td>';
print '<td align="right" nowrap><input size="2" type="text" name="remise_percent" value="'.$objp->remise_percent.'">%</td>'; print '<td align="right" nowrap><input size="2" type="text" name="remise_percent" value="'.$objp->remise_percent.'">%</td>';
print '<td align="center" colspan="4" valign="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; print '<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print '<br /><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td>'; print '<br /><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
print '</tr>' . "\n"; print '</tr>' . "\n";
/* /*
@ -943,10 +940,122 @@ if ($_GET['propalid'] > 0)
dolibarr_print_error($db); dolibarr_print_error($db);
} }
/*
* Lignes de remise
*/
// Remise relative
$var=!$var;
print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="action" value="setremisepercent">';
print '<input type="hidden" name="propalid" value="'.$propal->id.'">';
print '<tr class="liste_total"><td>';
print $langs->trans('CustomerRelativeDiscount');
if ($propal->brouillon) print ' <font style="font-weight: normal">('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')</font>';
print '</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td align="right"><font style="font-weight: normal">';
if ($_GET['action'] == 'editrelativediscount')
{
print '<input type="text" name="remise_percent" size="2" value="'.$propal->remise_percent.'">%';
}
else
{
print $propal->remise_percent?$propal->remise_percent.'%':'&nbsp;';
}
print '</font></td>';
print '<td align="right"><font style="font-weight: normal">';
if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone");
else print '&nbsp;';
print '</font></td>';
if ($_GET['action'] != 'editrelativediscount')
{
if ($propal->brouillon && $user->rights->propale->creer)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editrelativediscount&amp;propalid='.$propal->id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).'</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=setremisepercent&amp;rowid='.$objp->rowid.'">';
print img_delete();
print '</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
print '<td>&nbsp;</td>';
}
else
{
print '<td colspan="3"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
}
print '</tr>';
print '</form>';
// Remise absolue
$var=!$var;
print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="action" value="setremiseabsolue">';
print '<input type="hidden" name="propalid" value="'.$propal->id.'">';
print '<tr class="liste_total"><td>';
print $langs->trans('CustomerAbsoluteDiscount');
if ($propal->brouillon) print ' <font style="font-weight: normal">('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')</font>';
print '</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td align="right"><font style="font-weight: normal">';
if ($_GET['action'] == 'editabsolutediscount')
{
print '-<input type="text" name="remise_absolue" size="2" value="'.$propal->remise_absolue.'">';
}
else
{
print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone");
}
print '</font></td>';
if ($_GET['action'] != 'editabsolutediscount')
{
if ($propal->brouillon && $user->rights->propale->creer)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editabsolutediscount&amp;propalid='.$propal->id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).'</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=setremiseabsolue&amp;rowid='.$objp->rowid.'">';
print img_delete();
print '</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
print '<td>&nbsp;</td>';
}
else
{
print '<td colspan="3"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
}
print '</tr>';
print '</form>';
/* /*
* Ajouter une ligne * Ajouter une ligne
*/ */
if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] <> 'editline') if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] <> 'editline')
{ {
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
@ -958,10 +1067,11 @@ if ($_GET['propalid'] > 0)
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
// Ajout produit produits/services personalisés // Ajout produit produits/services personalisés
print '<form action="propal.php?propalid='.$propal->id.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'" method="post">';
print '<input type="hidden" name="propalid" value="'.$propal->id.'">'; print '<input type="hidden" name="propalid" value="'.$propal->id.'">';
print '<input type="hidden" name="action" value="addligne">'; print '<input type="hidden" name="action" value="addligne">';
@ -982,7 +1092,7 @@ if ($_GET['propalid'] > 0)
print '<td align="right"><input type="text" size="5" name="np_price"></td>'; print '<td align="right"><input type="text" size="5" name="np_price"></td>';
print '<td align="right"><input type="text" size="2" value="1" name="qty"></td>'; print '<td align="right"><input type="text" size="2" value="1" name="qty"></td>';
print '<td align="right" nowrap><input type="text" size="2" value="'.$societe->remise_client.'" name="np_remise">%</td>'; print '<td align="right" nowrap><input type="text" size="2" value="'.$societe->remise_client.'" name="np_remise">%</td>';
print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addligne"></td>'; print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addligne"></td>';
print '</tr>'; print '</tr>';
print '</form>'; print '</form>';
@ -990,7 +1100,7 @@ if ($_GET['propalid'] > 0)
// Ajout de produits/services prédéfinis // Ajout de produits/services prédéfinis
if ($conf->produit->enabled) if ($conf->produit->enabled)
{ {
print '<form action="propal.php?propalid='.$propal->id.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'" method="post">';
print '<input type="hidden" name="propalid" value="'.$propal->id.'">'; print '<input type="hidden" name="propalid" value="'.$propal->id.'">';
print '<input type="hidden" name="action" value="addligne">'; print '<input type="hidden" name="action" value="addligne">';
@ -1013,7 +1123,7 @@ if ($_GET['propalid'] > 0)
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td align="right"><input type="text" size="2" name="qty" value="1"></td>'; print '<td align="right"><input type="text" size="2" name="qty" value="1"></td>';
print '<td align="right" nowrap><input type="text" size="2" name="remise" value="'.$societe->remise_client.'">%</td>'; print '<td align="right" nowrap><input type="text" size="2" name="remise" value="'.$societe->remise_client.'">%</td>';
print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans("Add").'" name="addligne"></td>'; print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans("Add").'" name="addligne"></td>';
print "</tr>\n"; print "</tr>\n";
print '</form>'; print '</form>';
@ -1036,7 +1146,7 @@ if ($_GET['propalid'] > 0)
*/ */
if ($_GET['action'] == 'statut') if ($_GET['action'] == 'statut')
{ {
print '<form action="propal.php?propalid='.$propal->id.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'" method="post">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td>'.$langs->trans('Note').'</td><td><textarea cols="60" rows="'.ROWS_3.'" wrap="soft" name="note">'; print '<tr><td>'.$langs->trans('Note').'</td><td><textarea cols="60" rows="'.ROWS_3.'" wrap="soft" name="note">';
print $propal->note; print $propal->note;
@ -1069,7 +1179,7 @@ if ($_GET['propalid'] > 0)
{ {
if ($user->rights->propale->valider) if ($user->rights->propale->valider)
{ {
print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=validate">'.$langs->trans('Validate').'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=validate">'.$langs->trans('Validate').'</a>';
} }
} }
@ -1078,7 +1188,7 @@ if ($_GET['propalid'] > 0)
{ {
if ($user->rights->propale->creer) if ($user->rights->propale->creer)
{ {
print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=modif">'.$langs->trans('Edit').'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=modif">'.$langs->trans('Edit').'</a>';
} }
} }
@ -1087,11 +1197,11 @@ if ($_GET['propalid'] > 0)
{ {
if ($propal->statut < 2) if ($propal->statut < 2)
{ {
print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=builddoc">'.$langs->trans("BuildPDF").'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=builddoc">'.$langs->trans("BuildPDF").'</a>';
} }
else else
{ {
print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=builddoc">'.$langs->trans("RebuildPDF").'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=builddoc">'.$langs->trans("RebuildPDF").'</a>';
} }
} }
@ -1104,7 +1214,7 @@ if ($_GET['propalid'] > 0)
$file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf'; $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf';
if (file_exists($file)) if (file_exists($file))
{ {
print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=presend">'.$langs->trans('Send').'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=presend">'.$langs->trans('Send').'</a>';
} }
} }
} }
@ -1114,7 +1224,7 @@ if ($_GET['propalid'] > 0)
{ {
if ($propal->statut == 1 && $user->rights->propale->cloturer) if ($propal->statut == 1 && $user->rights->propale->cloturer)
{ {
print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=statut">'.$langs->trans('Close').'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=statut">'.$langs->trans('Close').'</a>';
} }
} }
@ -1123,7 +1233,7 @@ if ($_GET['propalid'] > 0)
{ {
if ($user->rights->propale->supprimer) if ($user->rights->propale->supprimer)
{ {
print '<a class="butActionDelete" href="propal.php?propalid='.$propal->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'; print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
} }
} }
@ -1340,15 +1450,15 @@ else
$i = 0; $i = 0;
print '<table class="liste" width="100%">'; print '<table class="liste" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans('Ref'),'propal.php','p.ref','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'',$sortfield); print_liste_field_titre($langs->trans('Ref'),$_SERVER["PHP_SELF"],'p.ref','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'',$sortfield);
print_liste_field_titre($langs->trans('Company'),'propal.php','s.nom','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'',$sortfield); print_liste_field_titre($langs->trans('Company'),$_SERVER["PHP_SELF"],'s.nom','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'',$sortfield);
print_liste_field_titre($langs->trans('Date'),'propal.php','p.datep','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="center"',$sortfield); print_liste_field_titre($langs->trans('Date'),$_SERVER["PHP_SELF"],'p.datep','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="center"',$sortfield);
print_liste_field_titre($langs->trans('DateEndPropalShort'),'propal.php','dfv','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="center"',$sortfield); print_liste_field_titre($langs->trans('DateEndPropalShort'),$_SERVER["PHP_SELF"],'dfv','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="center"',$sortfield);
print_liste_field_titre($langs->trans('Price'),'propal.php','p.price','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="right"',$sortfield); print_liste_field_titre($langs->trans('Price'),$_SERVER["PHP_SELF"],'p.price','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="right"',$sortfield);
print_liste_field_titre($langs->trans('Status'),'propal.php','p.fk_statut','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'align="right"',$sortfield); print_liste_field_titre($langs->trans('Status'),$_SERVER["PHP_SELF"],'p.fk_statut','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'align="right"',$sortfield);
print "</tr>\n"; print "</tr>\n";
// Lignes des champs de filtre // Lignes des champs de filtre
print '<form method="get" action="propal.php">'; print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td class="liste_titre" valign="right">'; print '<td class="liste_titre" valign="right">';
@ -1374,7 +1484,7 @@ else
$now = time(); $now = time();
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td><a href="propal.php?propalid='.$objp->propalid.'">'.img_object($langs->trans('ShowPropal'),'propal').' '.$objp->ref."</a></td>\n"; print '<td><a href="'.$_SERVER["PHP_SELF"].'?propalid='.$objp->propalid.'">'.img_object($langs->trans('ShowPropal'),'propal').' '.$objp->ref."</a></td>\n";
if ($objp->client == 1) if ($objp->client == 1)
{ {
@ -1392,9 +1502,9 @@ else
$m = strftime('%m',$objp->dp); $m = strftime('%m',$objp->dp);
print strftime('%d',$objp->dp)."\n"; print strftime('%d',$objp->dp)."\n";
print ' <a href="propal.php?year='.$y.'&amp;month='.$m.'">'; print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'&amp;month='.$m.'">';
print dolibarr_print_date($objp->dp,'%b')."</a>\n"; print dolibarr_print_date($objp->dp,'%b')."</a>\n";
print ' <a href="propal.php?year='.$y.'">'; print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'">';
print strftime('%Y',$objp->dp)."</a></td>\n"; print strftime('%Y',$objp->dp)."</a></td>\n";
// Date fin validite // Date fin validite

View File

@ -197,7 +197,7 @@ if ($_POST['action'] == 'add')
if ($facid > 0) if ($facid > 0)
{ {
Header('Location: facture.php?facid='.$facid); Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facid);
exit; exit;
} }
else else
@ -334,7 +334,7 @@ if ($_POST['action'] == 'add')
// Fin création facture, on l'affiche // Fin création facture, on l'affiche
if ($facid > 0) if ($facid > 0)
{ {
Header('Location: facture.php?facid='.$facid); Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facid);
exit; exit;
} }
} }
@ -419,7 +419,7 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST
if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST['cancel'] == $langs->trans('Cancel')) if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST['cancel'] == $langs->trans('Cancel'))
{ {
Header('Location: facture.php?facid='.$_POST['facid']); // Pour réaffichage de la fiche en cours d'édition Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_POST['facid']); // Pour réaffichage de la fiche en cours d'édition
exit; exit;
} }
@ -437,7 +437,7 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')
$fac = new Facture($db); $fac = new Facture($db);
$result = $fac->delete($_GET['facid']); $result = $fac->delete($_GET['facid']);
$_GET['facid'] = 0 ; $_GET['facid'] = 0 ;
Header('Location: facture.php'); Header('Location: '.$_SERVER["PHP_SELF"]);
exit; exit;
} }
} }
@ -564,7 +564,7 @@ if ($_POST['action'] == 'send' || $_POST['action'] == 'relance')
else else
{ {
// Renvoie sur la fiche // Renvoie sur la fiche
Header('Location: facture.php?facid='.$fac->id.'&msg='.urlencode($msg)); Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&msg='.urlencode($msg));
exit; exit;
} }
} }
@ -682,7 +682,7 @@ if ($_GET['action'] == 'create')
} }
print '<form name="add" action="facture.php" method="post">'; print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n"; print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n";
print '<input name="facnumber" type="hidden" value="provisoire">'; print '<input name="facnumber" type="hidden" value="provisoire">';
@ -1388,7 +1388,7 @@ else
if ($fac->brouillon == 1 && $user->rights->facture->creer) if ($fac->brouillon == 1 && $user->rights->facture->creer)
{ {
print '<form action="facture.php?facid='.$fac->id.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'" method="post">';
print '<input type="hidden" name="action" value="set_ref_client">'; print '<input type="hidden" name="action" value="set_ref_client">';
print '<td colspan="3"><input type="text" name="ref_client" size="20" value="'.$fac->ref_client.'">'; print '<td colspan="3"><input type="text" name="ref_client" size="20" value="'.$fac->ref_client.'">';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'"></td>'; print '<input type="submit" class="button" value="'.$langs->trans('Modify').'"></td>';
@ -1452,7 +1452,7 @@ else
print '</td>'; print '</td>';
if ($_GET['action'] != 'classer') if ($_GET['action'] != 'classer')
{ {
print '<td align="right"><a href="facture.php?action=classer&amp;facid='.$fac->id.'">'; print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classer&amp;facid='.$fac->id.'">';
print img_edit($langs->trans('SetProject'),1); print img_edit($langs->trans('SetProject'),1);
print '</a></td>'; print '</a></td>';
} }
@ -1509,7 +1509,9 @@ else
print '<td align="right" width="50">'.$langs->trans('Qty').'</td>'; print '<td align="right" width="50">'.$langs->trans('Qty').'</td>';
print '<td align="right" width="50">'.$langs->trans('Discount').'</td>'; print '<td align="right" width="50">'.$langs->trans('Discount').'</td>';
print '<td align="right" width="50">'.$langs->trans('AmountHT').'</td>'; print '<td align="right" width="50">'.$langs->trans('AmountHT').'</td>';
print '<td width="16">&nbsp;</td><td width="16">&nbsp;</td><td width="16">&nbsp;</td>'; print '<td width="16">&nbsp;</td>';
print '<td width="16">&nbsp;</td>';
print '<td width="16">&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
} }
@ -1562,22 +1564,22 @@ else
// Icone d'edition et suppression // Icone d'edition et suppression
if ($fac->statut == 0 && $user->rights->facture->creer) if ($fac->statut == 0 && $user->rights->facture->creer)
{ {
print '<td align="right"><a href="facture.php?facid='.$fac->id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">'; print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">';
print img_edit(); print img_edit();
print '</a></td>'; print '</a></td>';
print '<td align="right"><a href="facture.php?facid='.$fac->id.'&amp;action=deleteline&amp;rowid='.$objp->rowid.'">'; print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=deleteline&amp;rowid='.$objp->rowid.'">';
print img_delete(); print img_delete();
print '</a></td>'; print '</a></td>';
print '<td align="right">'; print '<td align="right">';
if ($i > 0) if ($i > 0)
{ {
print '<a href="facture.php?facid='.$fac->id.'&amp;action=up&amp;rowid='.$objp->rowid.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=up&amp;rowid='.$objp->rowid.'">';
print img_up(); print img_up();
print '</a>'; print '</a>';
} }
if ($i < $num_lignes-1) if ($i < $num_lignes-1)
{ {
print '<a href="facture.php?facid='.$fac->id.'&amp;action=down&amp;rowid='.$objp->rowid.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=down&amp;rowid='.$objp->rowid.'">';
print img_down(); print img_down();
print '</a>'; print '</a>';
} }
@ -1593,7 +1595,7 @@ else
// Ligne en mode update // Ligne en mode update
if ($_GET['action'] == 'editline' && $user->rights->facture->creer && $_GET['rowid'] == $objp->rowid) if ($_GET['action'] == 'editline' && $user->rights->facture->creer && $_GET['rowid'] == $objp->rowid)
{ {
print '<form name="updateligne" action="facture.php" method="post">'; print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="action" value="updateligne">'; print '<input type="hidden" name="action" value="updateligne">';
print '<input type="hidden" name="facid" value="'.$fac->id.'">'; print '<input type="hidden" name="facid" value="'.$fac->id.'">';
print '<input type="hidden" name="rowid" value="'.$_GET['rowid'].'">'; print '<input type="hidden" name="rowid" value="'.$_GET['rowid'].'">';
@ -1651,7 +1653,7 @@ else
// Remise relative // Remise relative
$var=!$var; $var=!$var;
print '<form name="updateligne" action="facture.php" method="post">'; print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="action" value="setremisepercent">'; print '<input type="hidden" name="action" value="setremisepercent">';
print '<input type="hidden" name="facid" value="'.$fac->id.'">'; print '<input type="hidden" name="facid" value="'.$fac->id.'">';
print '<tr class="liste_total"><td>'; print '<tr class="liste_total"><td>';
@ -1687,7 +1689,7 @@ else
} }
if ($fac->brouillon && $user->rights->facture->creer && $fac->remise_percent) if ($fac->brouillon && $user->rights->facture->creer && $fac->remise_percent)
{ {
print '<td align="right"><a href="facture.php?facid='.$fac->id.'&amp;action=setremisepercent&amp;rowid='.$objp->rowid.'">'; print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=setremisepercent&amp;rowid='.$objp->rowid.'">';
print img_delete(); print img_delete();
print '</a></td>'; print '</a></td>';
} }
@ -1706,7 +1708,7 @@ else
// Remise absolue // Remise absolue
$var=!$var; $var=!$var;
print '<form name="updateligne" action="facture.php" method="post">'; print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="action" value="setremiseabsolue">'; print '<input type="hidden" name="action" value="setremiseabsolue">';
print '<input type="hidden" name="facid" value="'.$fac->id.'">'; print '<input type="hidden" name="facid" value="'.$fac->id.'">';
print '<tr class="liste_total"><td>'; print '<tr class="liste_total"><td>';
@ -1739,7 +1741,7 @@ else
} }
if ($fac->brouillon && $user->rights->facture->creer && $fac->remise_absolue) if ($fac->brouillon && $user->rights->facture->creer && $fac->remise_absolue)
{ {
print '<td align="right"><a href="facture.php?facid='.$fac->id.'&amp;action=setremiseabsolue&amp;rowid='.$objp->rowid.'">'; print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=setremiseabsolue&amp;rowid='.$objp->rowid.'">';
print img_delete(); print img_delete();
print '</a></td>'; print '</a></td>';
} }
@ -1792,7 +1794,7 @@ else
print '<td align="right"><input type="text" name="pu" size="6"></td>'; print '<td align="right"><input type="text" name="pu" size="6"></td>';
print '<td align="right"><input type="text" name="qty" value="1" size="2"></td>'; print '<td align="right"><input type="text" name="qty" value="1" size="2"></td>';
print '<td align="right" nowrap><input type="text" name="remise_percent" size="1" value="0">%</td>'; print '<td align="right" nowrap><input type="text" name="remise_percent" size="1" value="0">%</td>';
print '<td align="center" valign="middle" rowspan="1" colspan="4"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>'; print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>'; print '</tr>';
if ($conf->service->enabled) if ($conf->service->enabled)
{ {
@ -1859,7 +1861,7 @@ else
{ {
if ($user->rights->facture->valider) if ($user->rights->facture->valider)
{ {
print ' <a class="butAction" href="facture.php?facid='.$fac->id.'&amp;action=valid">'.$langs->trans('Validate').'</a>'; print ' <a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=valid">'.$langs->trans('Validate').'</a>';
} }
} }
else else
@ -1869,11 +1871,11 @@ else
{ {
if ($fac->paye == 0) if ($fac->paye == 0)
{ {
print ' <a class="butAction" href="facture.php?facid='.$fac->id.'&amp;action=builddoc">'.$langs->trans('BuildPDF').'</a>'; print ' <a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=builddoc">'.$langs->trans('BuildPDF').'</a>';
} }
else else
{ {
print ' <a class="butAction" href="facture.php?facid='.$fac->id.'&amp;action=builddoc">'.$langs->trans('RebuildPDF').'</a>'; print ' <a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=builddoc">'.$langs->trans('RebuildPDF').'</a>';
} }
} }
} }
@ -1881,7 +1883,7 @@ else
// Supprimer // Supprimer
if ($fac->statut == 0 && $user->rights->facture->supprimer && $_GET['action'] != 'delete') if ($fac->statut == 0 && $user->rights->facture->supprimer && $_GET['action'] != 'delete')
{ {
print '<a class="butActionDelete" href="facture.php?facid='.$fac->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'; print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
} }
// Envoyer // Envoyer
@ -2279,7 +2281,7 @@ else
print '</tr>'; print '</tr>';
// Lignes des champs de filtre // Lignes des champs de filtre
print '<form method="get" action="facture.php">'; print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td class="liste_titre" valign="right">'; print '<td class="liste_titre" valign="right">';
print '<input class="flat" size="10" type="text" name="search_ref" value="'.$_GET['search_ref'].'">'; print '<input class="flat" size="10" type="text" name="search_ref" value="'.$_GET['search_ref'].'">';
@ -2308,8 +2310,8 @@ else
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td nowrap="nowrap"><a href="facture.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').'</a> '; print '<td nowrap="nowrap"><a href="'.$_SERVER["PHP_SELF"].'?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').'</a> ';
print '<a href="facture.php?facid='.$objp->facid.'">'.$objp->facnumber.'</a>'.$objp->increment; print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$objp->facid.'">'.$objp->facnumber.'</a>'.$objp->increment;
if ($objp->datelimite < (time() - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am) print img_warning($langs->trans('Late')); if ($objp->datelimite < (time() - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am) print img_warning($langs->trans('Late'));
print '</td>'; print '</td>';
@ -2319,9 +2321,9 @@ else
$y = strftime('%Y',$objp->df); $y = strftime('%Y',$objp->df);
$m = strftime('%m',$objp->df); $m = strftime('%m',$objp->df);
print strftime('%d',$objp->df); print strftime('%d',$objp->df);
print ' <a href="facture.php?year='.$y.'&amp;month='.$m.'">'; print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'&amp;month='.$m.'">';
print substr(strftime('%B',$objp->df),0,3).'</a>'; print substr(strftime('%B',$objp->df),0,3).'</a>';
print ' <a href="facture.php?year='.$y.'">'; print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'">';
print strftime('%Y',$objp->df).'</a></td>'; print strftime('%Y',$objp->df).'</a></td>';
} }
else else

View File

@ -1213,8 +1213,10 @@ class Facture
if ($user->rights->facture->creer) if ($user->rights->facture->creer)
{ {
$remise=price2num($remise);
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
$sql.= ' SET remise_percent = '.price2num($remise); $sql.= ' SET remise_percent = '.$remise;
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
if ($this->db->query($sql)) if ($this->db->query($sql))
@ -1244,8 +1246,10 @@ class Facture
if ($user->rights->facture->creer) if ($user->rights->facture->creer)
{ {
$remise=price2num($remise);
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
$sql.= ' SET remise_absolue = '.price2num($remise); $sql.= ' SET remise_absolue = '.$remise;
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
dolibarr_syslog("Facture::set_remise_absolue sql=$sql"); dolibarr_syslog("Facture::set_remise_absolue sql=$sql");

View File

@ -51,7 +51,6 @@ class Propal
var $author; var $author;
var $ref; var $ref;
var $datep; var $datep;
var $remise;
var $products; var $products;
var $products_qty; var $products_qty;
var $price; var $price;
@ -61,6 +60,9 @@ class Propal
var $cond_reglement_code; var $cond_reglement_code;
var $mode_reglement_id; var $mode_reglement_id;
var $mode_reglement_code; var $mode_reglement_code;
var $remise;
var $remise_percent;
var $remise_absolue;
var $note; var $note;
var $note_public; var $note_public;
@ -91,6 +93,8 @@ class Propal
$this->id = $propalid; $this->id = $propalid;
$this->products = array(); $this->products = array();
$this->remise = 0; $this->remise = 0;
$this->remise_percent = 0;
$this->remise_absolue = 0;
$langs->load("propals"); $langs->load("propals");
$this->labelstatut[0]=$langs->trans("PropalStatusDraft"); $this->labelstatut[0]=$langs->trans("PropalStatusDraft");
@ -108,9 +112,9 @@ class Propal
/** /**
* \brief Ajout d'un produit dans la proposition, en memoire dans l'objet * \brief Ajout d'un produit dans la proposition, en memoire dans l'objet
* \param idproduct id du produit à ajouter * \param idproduct Id du produit à ajouter
* \param qty quantité * \param qty Quantité
* \param remise_percent remise effectuée sur le produit * \param remise_percent Remise relative effectuée sur le produit
* \return void * \return void
* \see insert_product * \see insert_product
*/ */
@ -134,7 +138,7 @@ class Propal
* \brief Ajout d'un produit dans la proposition, en base * \brief Ajout d'un produit dans la proposition, en base
* \param idproduct Id du produit à ajouter * \param idproduct Id du produit à ajouter
* \param qty Quantité * \param qty Quantité
* \param remise_percent Remise effectuée sur le produit * \param remise_percent Remise relative effectuée sur le produit
* \param p_desc Descriptif optionnel * \param p_desc Descriptif optionnel
* \return int >0 si ok, <0 si ko * \return int >0 si ok, <0 si ko
* \see add_product * \see add_product
@ -382,8 +386,10 @@ class Propal
$this->db->begin(); $this->db->begin();
// Insertion dans la base // Insertion dans la base
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note, note_public, model_pdf, fin_validite, fk_cond_reglement, fk_mode_reglement, date_livraison) "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, fk_soc_contact, price, remise, remise_percent, remise_absolue,";
$sql.= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, 0,0,".$this->db->idate($this->datep).", now(), '$this->ref', $this->author,"; $sql.= " tva, total, datep, datec, ref, fk_user_author, note, note_public, model_pdf, fin_validite, fk_cond_reglement, fk_mode_reglement, date_livraison) ";
$sql.= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, $this->remise_percent, $this->remise_absolue,";
$sql.= " 0,0,".$this->db->idate($this->datep).", now(), '$this->ref', $this->author,";
$sql.= "'".addslashes($this->note)."',"; $sql.= "'".addslashes($this->note)."',";
$sql.= "'".addslashes($this->note_public)."',"; $sql.= "'".addslashes($this->note_public)."',";
$sql.= "'$this->modelpdf',".$this->db->idate($this->fin_validite).","; $sql.= "'$this->modelpdf',".$this->db->idate($this->fin_validite).",";
@ -474,20 +480,22 @@ class Propal
$i++; $i++;
} }
} }
$calculs = calcul_price($products, $this->remise_percent); $calculs = calcul_price($products, $this->remise_percent, $this->remise_absolue);
$this->remise = $calculs[3]; $this->total_remise = $calculs[3];
$this->amount_ht = $calculs[4];
$this->total_ht = $calculs[0]; $this->total_ht = $calculs[0];
$this->total_tva = $calculs[1]; $this->total_tva = $calculs[1];
$this->total_ttc = $calculs[2]; $this->total_ttc = $calculs[2];
$tvas = $calculs[5];
// Met a jour en base // Met a jour en base
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET";
$sql .= " price='". price2num($this->total_ht)."'"; $sql .= " price='". price2num($this->total_ht)."'";
$sql .= ", tva='". price2num($this->total_tva)."'"; $sql .= ", tva='". price2num($this->total_tva)."'";
$sql .= ", total='". price2num($this->total_ttc)."'"; $sql .= ", total='". price2num($this->total_ttc)."'";
$sql .= ", remise='".price2num($this->remise)."'"; $sql .= ", remise='".price2num($this->total_remise)."'";
$sql .=" WHERE rowid = $this->id"; $sql .=" WHERE rowid = ".$this->id;
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
@ -507,15 +515,15 @@ class Propal
*/ */
function fetch($rowid) function fetch($rowid)
{ {
$sql = "SELECT ref,total,price,remise,tva,fk_soc,fk_soc_contact"; $sql = "SELECT ref,total,price,remise,remise_percent,remise_absolue,tva,fk_soc,fk_soc_contact";
$sql.= ", ".$this->db->pdate("datep")."as dp"; $sql.= ", ".$this->db->pdate("datep")."as dp";
$sql.= ", ".$this->db->pdate("fin_validite")."as dfv, model_pdf"; $sql.= ", ".$this->db->pdate("fin_validite")."as dfv, model_pdf";
$sql.= ", note, note_public"; $sql.= ", note, note_public";
$sql.= ", fk_projet, fk_statut, remise_percent, fk_user_author"; $sql.= ", fk_projet, fk_statut, fk_user_author";
$sql.= ", fk_cond_reglement, fk_mode_reglement, date_livraison"; $sql.= ", fk_cond_reglement, fk_mode_reglement, date_livraison";
$sql.= ", c.label as statut_label"; $sql.= ", c.label as statut_label";
$sql.= " FROM ".MAIN_DB_PREFIX."propal"; $sql.= " FROM ".MAIN_DB_PREFIX."propal,";
$sql.= "," . MAIN_DB_PREFIX."c_propalst as c"; $sql.= " ".MAIN_DB_PREFIX."c_propalst as c";
$sql.= " WHERE fk_statut = c.id"; $sql.= " WHERE fk_statut = c.id";
$sql.= " AND rowid='".$rowid."';"; $sql.= " AND rowid='".$rowid."';";
@ -536,6 +544,7 @@ class Propal
$this->price = $obj->price; $this->price = $obj->price;
$this->remise = $obj->remise; $this->remise = $obj->remise;
$this->remise_percent = $obj->remise_percent; $this->remise_percent = $obj->remise_percent;
$this->remise_absolue = $obj->remise_absolue;
$this->total = $obj->total; $this->total = $obj->total;
$this->total_ht = $obj->price; $this->total_ht = $obj->price;
$this->total_tva = $obj->tva; $this->total_tva = $obj->tva;
@ -551,7 +560,7 @@ class Propal
$this->statut_libelle = $obj->statut_label; $this->statut_libelle = $obj->statut_label;
$this->cond_reglement_id = $obj->fk_cond_reglement; $this->cond_reglement_id = $obj->fk_cond_reglement;
$this->mode_reglement_id = $obj->fk_mode_reglement; $this->mode_reglement_id = $obj->fk_mode_reglement;
$this->date_livraison = $obj->date_livraison; $this->date_livraison = $obj->date_livraison;
$this->user_author_id = $obj->fk_user_author; $this->user_author_id = $obj->fk_user_author;
@ -737,10 +746,10 @@ class Propal
/** /**
* \brief Définit une remise globale sur la proposition * \brief Définit la date de fin de validité
* \param user Objet utilisateur qui modifie * \param user Objet utilisateur qui modifie
* \param remise Montant remise * \param date_fin_validite Date fin
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function set_echeance($user, $date_fin_validite) function set_echeance($user, $date_fin_validite)
{ {
@ -761,7 +770,8 @@ class Propal
} }
} }
} }
/**
/**
* \brief Définit une date de livraison * \brief Définit une date de livraison
* \param user Objet utilisateur qui modifie * \param user Objet utilisateur qui modifie
* \param date_livraison date de livraison * \param date_livraison date de livraison
@ -790,13 +800,15 @@ class Propal
/** /**
* \brief Définit une remise globale sur la proposition * \brief Définit une remise globale relative sur la proposition
* \param user Objet utilisateur qui modifie * \param user Objet utilisateur qui modifie
* \param remise Montant remise * \param remise Montant remise
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function set_remise($user, $remise) function set_remise_percent($user, $remise)
{ {
$remise=trim($remise)?trim($remise):0;
if ($user->rights->propale->creer) if ($user->rights->propale->creer)
{ {
$remise = price2num($remise); $remise = price2num($remise);
@ -813,20 +825,53 @@ class Propal
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dolibarr_syslog("Propal::set_remise Erreur SQL"); dolibarr_syslog("Propal::set_remise_percent Error sql=$sql");
return -1; return -1;
} }
} }
} }
/* /**
* * \brief Définit une remise globale absolue sur la proposition
* * \param user Objet utilisateur qui modifie
* * \param remise Montant remise
*/ * \return int <0 si ko, >0 si ok
function set_project($user, $project_id) */
{ function set_remise_absolue($user, $remise)
{
$remise=trim($remise)?trim($remise):0;
if ($user->rights->propale->creer)
{
$remise = price2num($remise);
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
$sql.= " SET remise_absolue = ".$remise;
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
if ($this->db->query($sql) )
{
$this->remise_absolue = $remise;
$this->update_price();
return 1;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Propal::set_remise_absolue Error sql=$sql");
return -1;
}
}
}
/*
*
*
*
*/
function set_project($user, $project_id)
{
if ($user->rights->propale->creer) if ($user->rights->propale->creer)
{ {
//verif que le projet et la société concordent //verif que le projet et la société concordent
@ -1190,10 +1235,10 @@ class Propal
*/ */
function delete($user) function delete($user)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = $this->id ;"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id;
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = $this->id;"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
dolibarr_syslog("Suppression de la proposition $this->id par $user->fullname ($user->id)"); dolibarr_syslog("Suppression de la proposition $this->id par $user->fullname ($user->id)");
@ -1503,6 +1548,7 @@ class Propal
$this->price = $src_propal->price; $this->price = $src_propal->price;
$this->remise = $src_propal->remise; $this->remise = $src_propal->remise;
$this->remise_percent = $src_propal->remise_percent; $this->remise_percent = $src_propal->remise_percent;
$this->remise_absolue = $src_propal->remise_absolue;
$this->total = $src_propal->total; $this->total = $src_propal->total;
$this->total_ht = $src_propal->total_ht; $this->total_ht = $src_propal->total_ht;
$this->total_tva = $src_propal->total_tva; $this->total_tva = $src_propal->total_tva;
@ -1541,8 +1587,10 @@ class Propal
$this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600); $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
// Insertion dans la base // Insertion dans la base
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note, note_public, model_pdf, fin_validite, fk_cond_reglement, fk_mode_reglement, date_livraison) "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, fk_soc_contact, price, remise, remise_percent, remise_absolue,";
$sql.= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, 0,0,".$this->db->idate($this->datep).", now(), '$this->ref', $this->author,"; $sql.= " tva, total, datep, datec, ref, fk_user_author, note, note_public, model_pdf, fin_validite, fk_cond_reglement, fk_mode_reglement, date_livraison) ";
$sql.= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, $this->remise_percent, $this->remise_absolue,";
$sql.= " 0,0,".$this->db->idate($this->datep).", now(), '$this->ref', $this->author,";
$sql.= "'".addslashes($this->note)."',"; $sql.= "'".addslashes($this->note)."',";
$sql.= "'".addslashes($this->note_public)."',"; $sql.= "'".addslashes($this->note_public)."',";
$sql.= "'$this->modelpdf',".$this->db->idate($this->fin_validite).","; $sql.= "'$this->modelpdf',".$this->db->idate($this->fin_validite).",";