Fix: When creating invoice from other object, discount are created
automatically
This commit is contained in:
parent
0bee52f161
commit
9f5219ee77
@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
@ -19,8 +19,7 @@
|
||||
/**
|
||||
* \file htdocs/comm/remise.php
|
||||
* \ingroup societe
|
||||
* \brief Onglet remise de la societe
|
||||
* \version $Id: remise.php,v 1.35 2011/08/03 00:46:27 eldy Exp $
|
||||
* \brief Page to edit relative discount of a customer
|
||||
*/
|
||||
|
||||
require("../main.inc.php");
|
||||
@ -31,15 +30,25 @@ $langs->load("companies");
|
||||
$langs->load("orders");
|
||||
$langs->load("bills");
|
||||
|
||||
$_socid = $_GET["id"];
|
||||
$socid = GETPOST("id");
|
||||
// Security check
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
$_socid = $user->societe_id;
|
||||
$socid = $user->societe_id;
|
||||
}
|
||||
|
||||
|
||||
if ($_POST["action"] == 'setremise')
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if (GETPOST('cancel') && GETPOST('backtopage'))
|
||||
{
|
||||
Header("Location: ".GETPOST("backtopage"));
|
||||
exit;
|
||||
}
|
||||
|
||||
if (GETPOST("action") == 'setremise')
|
||||
{
|
||||
$soc = New Societe($db);
|
||||
$soc->fetch($_GET["id"]);
|
||||
@ -47,8 +56,16 @@ if ($_POST["action"] == 'setremise')
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
Header("Location: remise.php?id=".$_GET["id"]);
|
||||
exit;
|
||||
if (GETPOST('backtopage'))
|
||||
{
|
||||
Header("Location: ".GETPOST('backtopage'));
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
Header("Location: remise.php?id=".$_GET["id"]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -71,21 +88,15 @@ llxHeader();
|
||||
* Mode fiche
|
||||
*
|
||||
*********************************************************************************/
|
||||
if ($_socid > 0)
|
||||
if ($socid > 0)
|
||||
{
|
||||
// On recupere les donnees societes par l'objet
|
||||
$objsoc = new Societe($db);
|
||||
$objsoc->id=$_socid;
|
||||
$objsoc->fetch($_socid,$to);
|
||||
$objsoc->id=$socid;
|
||||
$objsoc->fetch($socid);
|
||||
|
||||
if ($errmesg)
|
||||
{
|
||||
print '<div class="error">'.$errmesg.'</div><br>';
|
||||
}
|
||||
dol_htmloutput_errors($errmesg);
|
||||
|
||||
/*
|
||||
* Affichage onglets
|
||||
*/
|
||||
$head = societe_prepare_head($objsoc);
|
||||
|
||||
dol_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"),0,'company');
|
||||
@ -111,6 +122,7 @@ if ($_socid > 0)
|
||||
print '<form method="POST" action="remise.php?id='.$objsoc->id.'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="setremise">';
|
||||
print '<input type="hidden" name="backtopage" value="'.GETPOST('backtopage').'">';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
@ -122,13 +134,21 @@ if ($_socid > 0)
|
||||
print '<tr><td colspan="2" width="25%">';
|
||||
print $langs->trans("NoteReason").'</td><td colspan="2"><input type="text" size="60" name="note" value="'.$_POST["note"].'"></td></tr>';
|
||||
|
||||
print '<tr><td colspan="4" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
|
||||
|
||||
print "</table>";
|
||||
|
||||
print '<center>';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
||||
if (GETPOST("backtopage"))
|
||||
{
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
}
|
||||
print '</center>';
|
||||
|
||||
print "</form>";
|
||||
|
||||
print "</div>\n";
|
||||
dol_fiche_end();
|
||||
|
||||
print '<br>';
|
||||
|
||||
|
||||
@ -180,5 +200,5 @@ if ($_socid > 0)
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date: 2011/08/03 00:46:27 $ - $Revision: 1.35 $');
|
||||
llxFooter();
|
||||
?>
|
||||
|
||||
@ -21,7 +21,6 @@
|
||||
* \file htdocs/comm/remx.php
|
||||
* \ingroup societe
|
||||
* \brief Page to edit absolute discounts for a customer
|
||||
* \version $Id: remx.php,v 1.53 2011/08/04 21:46:51 eldy Exp $
|
||||
*/
|
||||
|
||||
require("../main.inc.php");
|
||||
@ -34,10 +33,10 @@ $langs->load("bills");
|
||||
$langs->load("companies");
|
||||
|
||||
// Security check
|
||||
$_socid = $_GET["id"];
|
||||
$socid = GETPOST("id");
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
$_socid = $user->societe_id;
|
||||
$socid = $user->societe_id;
|
||||
}
|
||||
|
||||
|
||||
@ -205,16 +204,16 @@ if (GETPOST("action") == 'confirm_remove' && GETPOST("confirm")=='yes')
|
||||
$form=new Form($db);
|
||||
$facturestatic=new Facture($db);
|
||||
|
||||
llxHeader();
|
||||
llxHeader('',$langs->trans("GlobalDiscount"));
|
||||
|
||||
if ($_socid > 0)
|
||||
if ($socid > 0)
|
||||
{
|
||||
dol_htmloutput_mesg($mesg);
|
||||
|
||||
// On recupere les donnees societes par l'objet
|
||||
$objsoc = new Societe($db);
|
||||
$objsoc->id=$_socid;
|
||||
$objsoc->fetch($_socid,$to);
|
||||
$objsoc->id=$socid;
|
||||
$objsoc->fetch($socid);
|
||||
|
||||
/*
|
||||
* Affichage onglets
|
||||
@ -257,10 +256,10 @@ if ($_socid > 0)
|
||||
}
|
||||
|
||||
print '<tr><td width="38%">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>';
|
||||
print '<td>'.$remise_all.' '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
||||
print '<td>'.$remise_all.' '.$langs->trans("Currency".$conf->monnaie).' '.$langs->trans("HT").'</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("CustomerAbsoluteDiscountMy").'</td>';
|
||||
print '<td>'.$remise_user.' '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
||||
print '<td>'.$remise_user.' '.$langs->trans("Currency".$conf->monnaie).' '.$langs->trans("HT").'</td></tr>';
|
||||
print '</table>';
|
||||
print '<br>';
|
||||
|
||||
@ -270,23 +269,25 @@ if ($_socid > 0)
|
||||
print '<td><input type="text" size="5" name="amount_ht" value="'.$_POST["amount_ht"].'"> '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
|
||||
print '<tr><td width="38%">'.$langs->trans("VAT").'</td>';
|
||||
print '<td>';
|
||||
print $form->load_tva('tva_tx','0','',$mysoc,'');
|
||||
print $form->load_tva('tva_tx',GETPOST('tva_tx'),'',$mysoc,'');
|
||||
print '</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("NoteReason").'</td>';
|
||||
print '<td><input type="text" size="60" name="desc" value="'.$_POST["desc"].'"></td></tr>';
|
||||
|
||||
print '<tr><td align="center" colspan="2">';
|
||||
print "</table>";
|
||||
|
||||
print '<center>';
|
||||
print '<input type="submit" class="button" name="submit" value="'.$langs->trans("AddGlobalDiscount").'">';
|
||||
if (GETPOST("backtopage"))
|
||||
{
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
}
|
||||
print '</td></tr>';
|
||||
print '</center>';
|
||||
|
||||
print "</table></form>";
|
||||
print '</form>';
|
||||
|
||||
print "</div>\n";
|
||||
dol_fiche_end();
|
||||
|
||||
print '<br>';
|
||||
|
||||
@ -538,5 +539,5 @@ if ($_socid > 0)
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date: 2011/08/04 21:46:51 $ - $Revision: 1.53 $');
|
||||
llxFooter();
|
||||
?>
|
||||
|
||||
@ -734,14 +734,33 @@ if ($action == 'add' && $user->rights->facture->creer)
|
||||
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
|
||||
|
||||
$fk_parent_line=0;
|
||||
$num=sizeof($lines);
|
||||
$num=count($lines);
|
||||
|
||||
for ($i=0;$i<$num;$i++)
|
||||
{
|
||||
if ($lines[$i]->subprice < 0)
|
||||
{
|
||||
// Negative line, we create a discount line
|
||||
// TODO
|
||||
$discount = new DiscountAbsolute($db);
|
||||
$discount->fk_soc=$object->socid;
|
||||
$discount->amount_ht=abs($lines[$i]->total_ht);
|
||||
$discount->amount_tva=abs($lines[$i]->total_tva);
|
||||
$discount->amount_ttc=abs($lines[$i]->total_ttc);
|
||||
$discount->tva_tx=$lines[$i]->tva_tx;
|
||||
$discount->fk_user=$user->id;
|
||||
$discount->description=$desc;
|
||||
$discountid=$discount->create($user);
|
||||
if ($discountid > 0)
|
||||
{
|
||||
$result=$object->insert_discount($discountid);
|
||||
//$result=$discount->link_to_invoice($lineid,$id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$discount->error;
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -791,8 +810,13 @@ if ($action == 'add' && $user->rights->facture->creer)
|
||||
$fk_parent_line
|
||||
);
|
||||
|
||||
if ($result < 0)
|
||||
if ($result > 0)
|
||||
{
|
||||
$lineid=$result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$lineid=0;
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
@ -956,7 +980,7 @@ if (($action == 'addline' || $action == 'addline_predef') && $user->rights->fact
|
||||
}
|
||||
|
||||
$desc = $prod->description;
|
||||
$desc.= ($prod->description && $_POST['np_desc']) ? ((dol_textishtml($prod->description) || dol_textishtml($_POST['np_desc']))?"<br />\n":"\n") : "";
|
||||
$desc.= ($prod->description && $_POST['np_desc']) ? ((dol_textishtml($prod->description) || dol_textishtml($_POST['np_desc']))?"<br>\n":"\n") : "";
|
||||
$desc.= $_POST['np_desc'];
|
||||
if (! empty($prod->customcode) || ! empty($prod->country_code))
|
||||
{
|
||||
@ -965,7 +989,7 @@ if (($action == 'addline' || $action == 'addline_predef') && $user->rights->fact
|
||||
if (! empty($prod->customcode) && ! empty($prod->country_code)) $tmptxt.=' - ';
|
||||
if (! empty($prod->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code,0,$db,$langs,0);
|
||||
$tmptxt.=')';
|
||||
$desc.= (dol_textishtml($desc)?"<br />\n":"\n").$tmptxt;
|
||||
$desc.= (dol_textishtml($desc)?"<br>\n":"\n").$tmptxt;
|
||||
}
|
||||
$type = $prod->type;
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ class DiscountAbsolute
|
||||
var $error;
|
||||
|
||||
var $id; // Id remise
|
||||
var $fk_soc;
|
||||
var $amount_ht; //
|
||||
var $amount_tva; //
|
||||
var $amount_ttc; //
|
||||
|
||||
Loading…
Reference in New Issue
Block a user