diff --git a/htdocs/comm/remise.php b/htdocs/comm/remise.php index 225398bfa23..2722ae7b426 100644 --- a/htdocs/comm/remise.php +++ b/htdocs/comm/remise.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * * 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 '
'.$errmesg.'

'; - } + 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 '
'; print ''; print ''; + print ''; print ''; @@ -122,13 +134,21 @@ if ($_socid > 0) print ''; - print ''; - print "
'; print $langs->trans("NoteReason").'
"; + print '
'; + print ''; + if (GETPOST("backtopage")) + { + print '    '; + print ''; + } + print '
'; + print "
"; - print "\n"; + dol_fiche_end(); + print '
'; @@ -180,5 +200,5 @@ if ($_socid > 0) $db->close(); -llxFooter('$Date: 2011/08/03 00:46:27 $ - $Revision: 1.35 $'); +llxFooter(); ?> diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index d836864b7bb..e6b79bc44bc 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -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 ''.$langs->trans("CustomerAbsoluteDiscountAllUsers").''; - print ''.$remise_all.' '.$langs->trans("Currency".$conf->monnaie).''; + print ''.$remise_all.' '.$langs->trans("Currency".$conf->monnaie).' '.$langs->trans("HT").''; print ''.$langs->trans("CustomerAbsoluteDiscountMy").''; - print ''.$remise_user.' '.$langs->trans("Currency".$conf->monnaie).''; + print ''.$remise_user.' '.$langs->trans("Currency".$conf->monnaie).' '.$langs->trans("HT").''; print ''; print '
'; @@ -270,23 +269,25 @@ if ($_socid > 0) print ' '.$langs->trans("Currency".$conf->monnaie).''; print ''.$langs->trans("VAT").''; print ''; - print $form->load_tva('tva_tx','0','',$mysoc,''); + print $form->load_tva('tva_tx',GETPOST('tva_tx'),'',$mysoc,''); print ''; print ''.$langs->trans("NoteReason").''; print ''; - print ''; + print ""; + + print '
'; print ''; if (GETPOST("backtopage")) { print '    '; print ''; } - print ''; + print '
'; - print ""; + print ''; - print "\n"; + dol_fiche_end(); print '
'; @@ -538,5 +539,5 @@ if ($_socid > 0) $db->close(); -llxFooter('$Date: 2011/08/04 21:46:51 $ - $Revision: 1.53 $'); +llxFooter(); ?> diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index c8c1516b9ad..f98efed5e94 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -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']))?"
\n":"\n") : ""; + $desc.= ($prod->description && $_POST['np_desc']) ? ((dol_textishtml($prod->description) || dol_textishtml($_POST['np_desc']))?"
\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)?"
\n":"\n").$tmptxt; + $desc.= (dol_textishtml($desc)?"
\n":"\n").$tmptxt; } $type = $prod->type; } diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index f6c46e9ed46..91a35373b70 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -34,6 +34,7 @@ class DiscountAbsolute var $error; var $id; // Id remise + var $fk_soc; var $amount_ht; // var $amount_tva; // var $amount_ttc; //